- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我的代码
private void graphToolStripMenuItem_Click(object sender, EventArgs e)
{
button1.Visible = false;
button2.Visible = false;
button3.Visible = false;
button4.Visible = false;
label1.Visible = false;
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = true;
gg = this.CreateGraphics();
p3 = new Pen(Color.Blue,5);
b1 = new SolidBrush(Color.Red);
p2 = new Pen(Color.Red);
Font f=new Font("Arial",16);
float ox = this.ClientSize.Width / 2;
float oy = this.ClientSize.Height / 2;
gg.DrawLine(p3, ox - 500, oy, ox + 500, oy);
gg.DrawLine(p3, ox, oy + 300, ox, oy - 300);
gg.DrawString("Argument", f, b1, ox - 100, oy - 200);
gg.DrawString("<----f(Argument)---->", f, b1, ox + 100, oy + 100);
for (int i = 0; i < 1000; i++)
{
double tem1 = graphValuesCal();
double temp2 = functionCal();
gg.FillEllipse(b1, ox + (float)tem1/2,oy-20*(float)temp2, (float)5, (float)5);
Thread.Sleep(10);
}
}
当我运行这段代码时,图形被绘制出来,但是当循环完成图形以及字符串和线(轴)消失时。如果我注释掉这段代码
button1.Visible = false;
button2.Visible = false;
button3.Visible = false;
button4.Visible = false;
label1.Visible = false;
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;
label2.Visible = false;
label3.Visible = false;
意味着如果所有这些控件之前都是可见的,那么当我单击 Graph menu
项时它们将保持可见。然后线条和图形不会消失这里可能有一些基本的东西,但我想我错过了那个。需要帮助
最佳答案
您的绘图应该在 OnPaint
事件方法中完成。
在你的窗体上加入 OnPaint
事件并将你的绘画添加到该方法中,如下所示:
// Put this in your constructor, or use VisualStudio to create the method for you
this.Paint += new System.Windows.Forms.PaintEventHandler(this.paint_Method);
private void paint_Method(object sender, PaintEventArgs e)
{
gg = e.Graphics;
p3 = new Pen(Color.Blue,5);
b1 = new SolidBrush(Color.Red);
p2 = new Pen(Color.Red);
Font f=new Font("Arial",16);
float ox = this.ClientSize.Width / 2;
float oy = this.ClientSize.Height / 2;
gg.DrawLine(p3, ox - 500, oy, ox + 500, oy);
gg.DrawLine(p3, ox, oy + 300, ox, oy - 300);
gg.DrawString("Argument", f, b1, ox - 100, oy - 200);
gg.DrawString("<----f(Argument)---->", f, b1, ox + 100, oy + 100);
for (int i = 0; i < 1000; i++)
{
double tem1 = graphValuesCal();
double temp2 = functionCal();
gg.FillEllipse(b1, ox + (float)tem1/2,oy-20*(float)temp2, 5f, 5f);
// Thread.Sleep(10);
}
}
您可能还想在 graphToolStripMenuItem_Click
方法中调用 this.Invalidate()
,请记住,我移至此处的代码应该从该方法中删除.
关于c# - 如果窗体上没有其他控件,图表就会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11766191/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!