2011-08-12 45 views
0
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功能我不知道如何調用該函數Picturebox_paint ...在文本框中的事件,或者是不可能的我怎麼能畫一些在PictureBox從EL

回答

1

有很多的東西錯了++你可以使用它。但你開始修復它:

 if (sw == 0) pictureBox1.Invalidate(); 
0

也許你應該創建一個方法:

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(); } 
...