vb.net Drawing bitmap on the form -


i want draw directly on form colored bitmap.but doesn't work.this code:

public class form1 ''declarations dim bmp new drawing.bitmap(11, 121) dim g drawing.graphics = drawing.graphics.fromimage(bmp)  private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click     g.fillrectangle(brushes.black, 0, 0, me.width, me.height)     g.drawimage(bmp, 0, 0, 111, 11)     g.drawline(pens.black, 0, 11, 111, 12)  end sub 

end class

you drawing bitmap onto itself, why code won't work. i'd suggest using e.graphics drawing, per se:

public class form1     ''declarations     dim haspainted boolean = false     dim bmp new drawing.bitmap(11, 121)     dim g drawing.graphics = drawing.graphics.fromimage(bmp)      private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click         haspainted = not haspainted          me.invalidate()     end sub      private sub form1_paint(sender object, e painteventargs) handles mybase.paint         if (haspainted)             e.graphics.fillrectangle(brushes.black, 0, 0, me.width, me.height)             e.graphics.drawline(pens.white, 0, 11, 111, 12)         end if     end sub end class 

the above code paints bitmap in paint event, unfortunately paint event called when form redrawn. button1 toggles haspainted boolean variable opposite of is, , check if haspainted true in paint event; means bitmap paint when button1 pressed.

me.invalidate() forces redraw of form, therefore repainting, why haspainted = not haspainted must before it.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -