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. C#
  4. Drawing over a picturebox

Drawing over a picturebox

Scheduled Pinned Locked Moved C#
tutorialcsharpgraphicsxmlhelp
2 Posts 2 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.
  • B Offline
    B Offline
    budidharma
    wrote on last edited by
    #1

    I have a c# program I've been writing which dynamically loads an image. It also dynamically loads an xml file which defines rectangles within the image. Each xml entry defines the upperleft coordinate on the image, and the width and height of the rectangle. What I need to do, is create outlines on the picturebox for each entry in the xml file. I'm not sure how to do this. Basically, over my loaded image, if there is an entry in the xml file, for example: 10,10, 50, 50 ... I need to draw a rectangle (outline, or full but semitransparent) over the picturebox at coordinates 10,10 width a height of 50 and width of 50. I've no idea where to start. Any help? Thanks.

    R 1 Reply Last reply
    0
    • B budidharma

      I have a c# program I've been writing which dynamically loads an image. It also dynamically loads an xml file which defines rectangles within the image. Each xml entry defines the upperleft coordinate on the image, and the width and height of the rectangle. What I need to do, is create outlines on the picturebox for each entry in the xml file. I'm not sure how to do this. Basically, over my loaded image, if there is an entry in the xml file, for example: 10,10, 50, 50 ... I need to draw a rectangle (outline, or full but semitransparent) over the picturebox at coordinates 10,10 width a height of 50 and width of 50. I've no idea where to start. Any help? Thanks.

      R Offline
      R Offline
      Rick Beideman
      wrote on last edited by
      #2

      Here is some code used in a paint event. If it is not in an event with PaintEventArgs you will need to get a Graphics object in another way. private void Image_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle selRect = new Rectangle(0,0,0,0); Graphics selGraphics = null; int lineThickness = 2; selGraphics = e.Graphics; selRect.X = 10; selRect.Y = 10; selRect.Width=50; selRect.Height=50; Pen selPen = new Pen(Color.Black, lineThickness); selGraphics.DrawRectangle(selPen, selRect); }

      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