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 rectangles - with the mouse.

Drawing rectangles - with the mouse.

Scheduled Pinned Locked Moved C#
graphicsquestion
14 Posts 4 Posters 2 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.
  • P Pedram Behroozi

    Hey, make your choice[^] ;)

    While (true) { Human.isLearnable = true; }

    D Offline
    D Offline
    dennycrane
    wrote on last edited by
    #5

    I looked at both of the links, seems it could be easier.

    P 1 Reply Last reply
    0
    • D dennycrane

      I looked at both of the links, seems it could be easier.

      P Offline
      P Offline
      Pedram Behroozi
      wrote on last edited by
      #6

      dennycrane wrote:

      I looked at both of the links

      Did you do that right now? You're amazing! :omg:

      dennycrane wrote:

      seems it could be easier.

      What do you mean? Do you have any idea?

      While (true) { Human.isLearnable = true; }

      D 1 Reply Last reply
      0
      • P Pedram Behroozi

        this[^] might help

        While (true) { Human.isLearnable = true; }

        P Offline
        P Offline
        Pedram Behroozi
        wrote on last edited by
        #7

        No, not suitable for your question but it's obvious!

        While (true) { Human.isLearnable = true; }

        1 Reply Last reply
        0
        • P Pedram Behroozi

          dennycrane wrote:

          I looked at both of the links

          Did you do that right now? You're amazing! :omg:

          dennycrane wrote:

          seems it could be easier.

          What do you mean? Do you have any idea?

          While (true) { Human.isLearnable = true; }

          D Offline
          D Offline
          dennycrane
          wrote on last edited by
          #8

          Yes, very simple. Click on a button then on a picturebox and a rectangle would appear.

          P 1 Reply Last reply
          0
          • D dennycrane

            What would be the easiest way of drawing rectangles or other shapes onto a picture box using the mouse? Just like in MS Paint.

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #9

            I did this using MouseDown, MouseMove, MouseUp and Paint event. And ofcourse a graphics object.

            "If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry

            D 1 Reply Last reply
            0
            • D dennycrane

              What would be the easiest way of drawing rectangles or other shapes onto a picture box using the mouse? Just like in MS Paint.

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #10

              See this: Draw with Mouse[^]

              Giorgi Dalakishvili #region signature My Articles / My Latest Article[^] / My blog[^] #endregion

              D 1 Reply Last reply
              0
              • G Giorgi Dalakishvili

                See this: Draw with Mouse[^]

                Giorgi Dalakishvili #region signature My Articles / My Latest Article[^] / My blog[^] #endregion

                D Offline
                D Offline
                dennycrane
                wrote on last edited by
                #11

                I know how to draw a line and I have that code, I don“t know how to get a rectangle or some other form to show on a picture box.

                1 Reply Last reply
                0
                • D dan sh

                  I did this using MouseDown, MouseMove, MouseUp and Paint event. And ofcourse a graphics object.

                  "If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry

                  D Offline
                  D Offline
                  dennycrane
                  wrote on last edited by
                  #12

                  could you give some examples?

                  D 1 Reply Last reply
                  0
                  • D dennycrane

                    could you give some examples?

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #13

                    Its too big of a code to share. Actually its all mixed with lot of other code that I use for drawing other stuff. I can tell bit of logic though. 1. Grab the coordinates at MouseDown 2. On MouseMove draw rectangles calculating the height and width using the graphics object. 3. On MouseUp get the point to find final hieght and width and keep them for using in Paint event. 4. Redraw final rectangle in Paint event. You can also place a PictureBox identical to final rectangle in case you want to have some events for the rectangle.

                    "If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry

                    1 Reply Last reply
                    0
                    • D dennycrane

                      Yes, very simple. Click on a button then on a picturebox and a rectangle would appear.

                      P Offline
                      P Offline
                      Pedram Behroozi
                      wrote on last edited by
                      #14

                      Well, it's too simple. I thought you said "like MS Paint" (actually you did!). However for your reason you should call PictureBox_Paint in Button_Click (be careful of parameters) and use e.Graphics.DrawRectangle(Pen pen, int x, int y, int width, int height) (+2 overload(s)) to draw a rectangle. Or you have something else to say? :^)

                      While (true) { Human.isLearnable = true; }

                      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