Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Not Able to draw line in Picture box

Not Able to draw line in Picture box

Scheduled Pinned Locked Moved Visual Basic
graphics
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kjsl2k9
    wrote on last edited by
    #1

    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

    I J C 3 Replies Last reply
    0
    • K kjsl2k9

      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

      I Offline
      I Offline
      i i i
      wrote on last edited by
      #2

      Download Visual Basic Power Pack 2 or 3 both available and it contains several controls like Line Shape , Rectangle, Oval Shape and Print form

      Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...

      1 Reply Last reply
      0
      • K kjsl2k9

        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

        J Offline
        J Offline
        Johan Hakkesteegt
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K kjsl2k9

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups