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. Can you Draw Shapes on Forms/PictureBoxes?

Can you Draw Shapes on Forms/PictureBoxes?

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 1 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.
  • Z Offline
    Z Offline
    ZeldaFreak
    wrote on last edited by
    #1

    I am making an app where you can click on an image (in a picturebox) to get X, Y, Width, and Height values. I would like to make it draw a rectangle of the specifyed X Y Width Height values on the PictureBox/Form once selected. Is this possible? Help is much appreciated, ~ZeldaFreak

    D 1 Reply Last reply
    0
    • Z ZeldaFreak

      I am making an app where you can click on an image (in a picturebox) to get X, Y, Width, and Height values. I would like to make it draw a rectangle of the specifyed X Y Width Height values on the PictureBox/Form once selected. Is this possible? Help is much appreciated, ~ZeldaFreak

      D Offline
      D Offline
      Daniel M Edwards
      wrote on last edited by
      #2

      You could always add code in the OnPaint event. If you just want to draw a single rectangle just declare a rectangle on the form object, then using mouse events once it is selected set the Selection Rectangle object to the appropriate values and then call this.Invalidate(); It will force a repaint of the object. Inside the paint routine you can have code to only bother drawing the rectangle if a selection has been made. The actual drawing of the rectangle can be done via the System.Windows.Forms.PaintEventArgs object which is passed to the routine. Simply use the e.Graphics.DrawRectangle(); method to draw the actual rectangle. An example of this called would be: e.Graphics.DrawRectangle(new Pen(Color.Red, 1), x, y, mySelection.Width, mySelection.Height); I am sure there is a better way out there but this should work.

      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