vb.net - Is there a faster way to draw dynamic rectangles in VB? -


i'm designing program have of same features ms paint in vb.net. following code allows me click-and-drag draw selection rectangle on picturebox, seems laggy (especially compared ms paint itself). there more efficient way of doing this?

public drawcapture boolean = false public drawcaptureorigin point public drawcapturerectangle rectangle  private sub picturebox1_mousedown(byval sender object, byval e system.windows.forms.mouseeventargs) handles picturebox1.mousedown     drawcapture = true     drawcaptureorigin = e.location     drawcapturerectangle = new rectangle(e.location, new point(1, 1)) end sub  private sub picturebox1_mousemove(byval sender object, byval e system.windows.forms.mouseeventargs) handles picturebox1.mousemove     dim curx integer = e.location.x, cury integer = e.location.y     dim dcox integer = drawcaptureorigin.x, dcoy integer = drawcaptureorigin.y     if drawcapture         if curx < dcox , cury < dcoy             drawcapturerectangle = new rectangle(curx, cury, dcox - curx, dcoy - cury)         elseif curx < dcox             drawcapturerectangle = new rectangle(curx, dcoy, dcox - curx, cury - dcoy)         elseif cury < dcoy             drawcapturerectangle = new rectangle(dcox, cury, curx - dcox, dcoy - cury)         else             drawcapturerectangle = new rectangle(dcox, dcoy, curx - dcox, cury - dcoy)         end if         picturebox1.invalidate()     end if end sub  private sub picturebox1_mouseup(byval sender object, byval e system.windows.forms.mouseeventargs) handles picturebox1.mouseup     drawcapture = false     picturebox1.invalidate() end sub  private sub picturebox1_paint(byval sender object, byval e system.windows.forms.painteventargs) handles picturebox1.paint     if drawcapturerectangle.width > 0         e.graphics.drawrectangle(pens.black, drawcapturerectangle)     end if end sub 

i cannot reproduce laggynes on pc, not sure if help, try enable double buffering. can set in form properties.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -