如何从其他地方调用picturebox_Paint函数
本文关键字:调用 picturebox 函数 Paint 其他 方调用 | 更新日期: 2023-09-27 18:05:42
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
char x;
int sw = 0;
if (e.KeyCode == Keys.Enter)
{
x = Convert.ToChar(textBox1.Text);
int i;
for (i = 0; i < n; i++)
if (x == litere[i]) { lb[i].Text = ""; lb[i].Text = Convert.ToString(x); sw = 1; }
if (sw == 0) { pictureBox1_Paint(???); }
}
}
美元 private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
wrong++;
Graphics g = CreateGraphics();
Brush b=new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Cross,Color.White,Color.Black);
if (wrong == 1) g.FillEllipse(b, 250, 125, 30, 30);
}
美元我不知道如何调用Picturebox_paint函数…在文本框的事件中,或者如果不可能,我如何从el
有很多事情是错误的。但是你开始用:
来修复它 if (sw == 0) pictureBox1.Invalidate();
也许你应该创建一个方法:
private void redraw()
{
wrong++;
Graphics g = CreateGraphics();
Brush b=new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Cross,Color.White,Color.Black);
if (wrong == 1) g.FillEllipse(b, 250, 125, 30, 30);
}
和
可以在任何地方使用private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
redraw();
}
和
...
if (sw == 0) { redraw(); }
...