Saturday, 15 September 2012

VB.NET Class method handles paint event -



VB.NET Class method handles paint event -

how can utilize clause handles in class method. illustration want draw image on picturebox1 code:

public class cell public sub draw_cell() handles picturebox1.paint code end sub end class

i have error:

handles clause requires withevents variable defined in containing type or 1 of base of operations types.

how can without using

private sub picturebox1_paint(byval sender object, byval e system.windows.forms.painteventargs) handles picturebox1.paint

ps. sorry bad english.

you can create own routines draw canvas.

option strict on alternative explicit on alternative infer off public class form1 private sub button1_click(sender object, e eventargs) handles button1.click dim canvas new bitmap(picturebox1.width, picturebox1.height) dim canvasgraphics graphics = graphics.fromimage(canvas) dim cellrect new rectangle(100, 100, 100, 100) cell.draw(canvasgraphics, cellrect, color.red, new pen(new solidbrush(color.green), 1)) picturebox1.image = canvas end sub public class cell public shared sub draw(byref canvasgraphics graphics, byval cellrect rectangle, byval fillcolor color, byval borderpen pen) dim renderedcell new bitmap(cellrect.width, cellrect.height, system.drawing.imaging.pixelformat.format32bppargb) dim borderrect new rectangle(0, 0, cellrect.width - 1, cellrect.height - 1) dim context bufferedgraphicscontext dim bgfx bufferedgraphics context = bufferedgraphicsmanager.current context.maximumbuffer = new size(cellrect.width + 1, cellrect.height + 1) bgfx = context.allocate(graphics.fromimage(renderedcell), new rectangle(0, 0, cellrect.width, cellrect.height)) dim g graphics = bgfx.graphics g.clear(fillcolor) g.drawrectangle(borderpen, borderrect) bgfx.render() canvasgraphics.drawimage(renderedcell, cellrect.location) end sub end class end class

vb.net

No comments:

Post a Comment