unnamed
unnamed

Reputation: 856

How to draw a rectangle on a form picturebox from another form

I have 2 forms.

  1. form = form1
  2. form = form2

When pressing a button in form1, form2 shows up. What I want is pressing a button in form2 draws a rectangle on to form1 picturebox.

I Wrote an event handler function for button clicked in Form2 to be handled in Form1, but in handler I can't draw anything in form1's picturebox.

How can I achieve it?

Upvotes: 2

Views: 863

Answers (1)

LarsTech
LarsTech

Reputation: 81620

In your event code on Form1 where you are receiving the button click event from Form2, try this:

using (Graphics g = Graphics.FromImage(pictureBox1.Image))
  g.FillRectangle(Brushes.Red, new Rectangle(10, 10, 32, 32));

pictureBox1.Invalidate();

Upvotes: 3

Related Questions