.net - Graphics.DrawRectangle Missing edge on 2nd screen -


i'm trying draw variable colour/width border on form (for 'across room' status reporting) draws fine except when maximised on non-primary displays...

when maximised on 2nd display don't left edge drawn shown here (green rect added debug, , appears draw ok).

i've tried numerous permutations of draw sequence, +/-1 pixel here , there, changing pen properties etc.. nothing seems work , fact works non maximised everywhere , maximised on primary screens makes me think it's bit more subtle.

complete code reproduce (single size-able form single button):

public class form2 private drawhighlightingrectangle boolean = false private highlightingrectanglecolour color = color.red  private sub form1_paint(sender object, e painteventargs) handles me.paint     if drawhighlightingrectangle         dim mypen new system.drawing.pen(highlightingrectanglecolour, 8)         mypen.alignment = drawing2d.penalignment.inset          e.graphics.clear(me.backcolor)          e.graphics.drawrectangle(mypen, 0, 0, me.clientrectangle.width, me.clientrectangle.height)          mypen.color = color.green         '    e.graphics.drawline(mypen, 0, 0, 0, 100)         e.graphics.drawrectangle(mypen, 0, 0, 100, 100)          mypen.dispose()     end if end sub  private sub form1_resize(sender object, e eventargs) handles me.resize     me.invalidate()     me.update() end sub  private sub button1_click(sender object, e eventargs) handles button1.click     drawhighlightingrectangle = not drawhighlightingrectangle     me.invalidate()     me.update() end sub end class 

debug of x,y , me.clientrectangle (it should clientrectangle i'm using, right?) sizes confirm they're correct.

any ideas?

edit:

changed me.clientrectangle.width var bit more in-depth debug, new complete code is;

public class form2 private drawhighlightingrectangle boolean = false private highlightingrectanglecolour color = color.red private mywidth = 1900  private sub form1_paint(sender object, e painteventargs) handles me.paint     if drawhighlightingrectangle         dim mypen new system.drawing.pen(highlightingrectanglecolour, 8)          e.graphics.clear(me.backcolor)          e.graphics.drawrectangle(mypen, 0, 0, mywidth, me.clientrectangle.height)          mypen.color = color.green         e.graphics.drawrectangle(mypen, 0, 0, 100, 100)          mypen.dispose()     end if end sub  private sub form1_resize(sender object, e eventargs) handles me.resize     me.invalidate()     me.update() end sub  private sub button1_click(sender object, e eventargs) handles button1.click     drawhighlightingrectangle = not drawhighlightingrectangle     me.invalidate()     me.update() end sub  private sub button2_click(sender object, e eventargs) handles button2.click     mywidth += 1     me.invalidate()     me.update() end sub end class 

(remember change mywidth 1900 match set-up!)

using approach can increment width , watch rect grow, when nearing correct full width left edge disappears - changing pen width affects when @ point disappear (i removed pen.alignment = inset in-case issue) either way cannot desired output...

looks bug. workaround, when full screened on non primary screen, should have topleft=pen.width-1. in other cases rectangle needs have topleft=cint(math.floor(pen.width/2)). make sure adjust width of rectangle accordingly

also, noticed cannot draw left margin pen wider 1 pixel. play around below sample code

public class form1     private drawhighlightingrectangle boolean = true     private highlightingrectanglecolour color = color.red     private penwidth = 1     dim mypen new system.drawing.pen(highlightingrectanglecolour, penwidth)      dim x = 0      private sub form1_load(sender object, e eventargs) handles mybase.load         text = "pen width = " & penwidth & ", x = " & x         mypen.alignment = drawing2d.penalignment.inset     end sub      private sub form1_paint(sender object, e painteventargs) handles me.paint         if drawhighlightingrectangle             e.graphics.clear(me.backcolor)             e.graphics.drawline(mypen, x, 100, x, 200)             e.graphics.drawline(mypen, cint(math.floor(penwidth / 2)), 10, cint(math.floor(penwidth / 2)), 100)         end if     end sub      private sub form1_resize(sender object, e eventargs) handles me.resize         me.invalidate()         me.update()     end sub      private sub button1_click(sender object, e eventargs) handles button1.click ' draw button         drawhighlightingrectangle = not drawhighlightingrectangle         me.invalidate()         me.update()     end sub      private sub button2_click(sender object, e eventargs) handles button2.click ' move right         x += 1         text = "pen width = " & penwidth & ", x = " & x         me.invalidate()         me.update()     end sub      private sub button3_click(sender object, e eventargs) handles button3.click ' increase pen width         penwidth += 1         mypen.dispose()         mypen = new system.drawing.pen(highlightingrectanglecolour, penwidth)         text = "pen width = " & penwidth & ", x = " & x         me.invalidate()         me.update()     end sub      private sub button4_click(sender object, e eventargs) handles button4.click ' reset width , x         penwidth = 1         x = 0         mypen.dispose()         mypen = new system.drawing.pen(highlightingrectanglecolour, penwidth)         text = "pen width = " & penwidth & ", x = " & x         me.invalidate()         me.update()     end sub      private sub button5_click(sender object, e eventargs) handles button5.click ' move left         x -= 1         text = "pen width = " & penwidth & ", x = " & x         me.invalidate()         me.update()     end sub end class 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -