Not Able to draw line in Picture box
-
Hi, I am trying to draw a line in picture box control using the following code in the Picturebox Paint Event : - Dim g As Graphics = MainPanel.CreateGraphics g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190)) But , unfortunately the line is not drawn can anybody tell the reason Thanks
-
Hi, I am trying to draw a line in picture box control using the following code in the Picturebox Paint Event : - Dim g As Graphics = MainPanel.CreateGraphics g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190)) But , unfortunately the line is not drawn can anybody tell the reason Thanks
-
Hi, I am trying to draw a line in picture box control using the following code in the Picturebox Paint Event : - Dim g As Graphics = MainPanel.CreateGraphics g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190)) But , unfortunately the line is not drawn can anybody tell the reason Thanks
Generally speaking the picturebox control is meant to display an image, not to draw in. If you want to draw a line, don't do it in the picturebox but rather on top of it. Alternatively, you could first create an image of the line and then load that image into the picturebox.
My advice is free, and you may get what you paid for.
-
Hi, I am trying to draw a line in picture box control using the following code in the Picturebox Paint Event : - Dim g As Graphics = MainPanel.CreateGraphics g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190)) But , unfortunately the line is not drawn can anybody tell the reason Thanks
kjsl2k9 wrote:
Dim g As Graphics = MainPanel.CreateGraphics g.DrawLine(Pens.Red, Convert.ToInt32(0), Convert.ToInt32(0), Convert.ToInt32(190), Convert.ToInt32(190))
All of this code is bad. Every last bit of it. Handle a paint event, never call CreateGraphics unless you're drawing a rubber band. Draw directly onto the form, not into a picture box, that's not what it's for. Use the graphics object passed into the paint event.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.