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. movable rectangle on image

movable rectangle on image

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 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.
  • R Offline
    R Offline
    R Myers
    wrote on last edited by
    #1

    Is there a way to draw a rectangle on top of a loaded image that a user can drag to create a selection area? I can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect. The image in the picturebox is rather large (10000x10000 pix give or take). Any help or pointers is much appreciated. R.Myers

    L P 2 Replies Last reply
    0
    • R R Myers

      Is there a way to draw a rectangle on top of a loaded image that a user can drag to create a selection area? I can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect. The image in the picturebox is rather large (10000x10000 pix give or take). Any help or pointers is much appreciated. R.Myers

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      R.Myers wrote:

      can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect.

      Do you use double buffering? First draw both the image and the rectangle to an offscreen surface and then present it on the screen. regards

      1 Reply Last reply
      0
      • R R Myers

        Is there a way to draw a rectangle on top of a loaded image that a user can drag to create a selection area? I can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect. The image in the picturebox is rather large (10000x10000 pix give or take). Any help or pointers is much appreciated. R.Myers

        P Offline
        P Offline
        PhilDanger
        wrote on last edited by
        #3

        If you're drawing onto the actual Image in the picturebox (IE through Graphics.FromImage() ) then the actual image is going to be edited and you won't be able to "clear" it without loading the image again (expensive for a huge image like that!). Instead what you should do is override the OnPaint event of the PictureBox and take its graphic region from the PaintEventArgs (PaintEventArgs.Graphics), and then do your drawing there.

        R 1 Reply Last reply
        0
        • P PhilDanger

          If you're drawing onto the actual Image in the picturebox (IE through Graphics.FromImage() ) then the actual image is going to be edited and you won't be able to "clear" it without loading the image again (expensive for a huge image like that!). Instead what you should do is override the OnPaint event of the PictureBox and take its graphic region from the PaintEventArgs (PaintEventArgs.Graphics), and then do your drawing there.

          R Offline
          R Offline
          R Myers
          wrote on last edited by
          #4

          Thanks PhilDanger & greeeg I'll take a look into these ideas R.Myers

          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