vb.net - Drawing rectangle on picture box from another form's button -


i have form picturebox on it, , form button on it. how picturebox1_paint on first form once press button on other form?

private sub picturebox1_paint(byval sender object, byval e system.windows.forms.painteventargs) handles picturebox1.paint     e.graphics.drawrectangle(pens.blue, x.text, y.text, width.text, height.text) end sub 

this have, need alter work?

at form1, add

sub paintimage(rectangle rectangle)     ' create image in size of picturebox1     dim image new bitmap(picturebox1.width, picturebox1.height)      ' paint on created image     using gr graphics = graphics.fromimage(image)         gr.drawrectangle(new pen(color.red), rectangle)                 end using      ' display finished image in picturebox1     picturebox1.image = image end sub 

and call form button:

sub button1_click(sender object, e eventargs) handles button1.click             form1.paintimage(new rectangle(x, y, width, height)) ' assume have x, y, w, h end sub 

you can delete paint() event handler shown in question. purpose repaint picturebox1.image if size or visibility changed , in cases can leave is.


Comments