Ionut Boicu
Ionut Boicu

Reputation: 3

How to call picturebox_Paint function from elsewhere

    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

Upvotes: 0

Views: 1678

Answers (2)

Hans Passant
Hans Passant

Reputation: 942010

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

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

Upvotes: 1

Pieniadz
Pieniadz

Reputation: 661

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

Upvotes: 0

Related Questions