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);

    }

$ I don't know how to call the Picturebox_paint function ... in the textbox's event or if is not possible how can I draw something in a picturebox from el

Pieniadz
  • 653
  • 3
  • 9
  • 22

2 Answers2

1

There are a lot of things wrong++. But you get started on fixing it with:

        if (sw == 0) pictureBox1.Invalidate(); 
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

Maybe you should create a Method:

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

and You can use it wherever you want

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    redraw();
}

and

...
if (sw == 0) { redraw(); }
...
Pieniadz
  • 653
  • 3
  • 9
  • 22