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 circles.

drawing circles.

Scheduled Pinned Locked Moved C#
graphicshelpquestion
13 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.
  • D dan sh

    Have you hardcoded the parameters in the DrawEllipse method? Following code works fine:

      gx.Clear(this.BackColor);
      gx = this.CreateGraphics();
      gx.DrawEllipse(Pens.Red, (this.Width / 2 - 10), (this.Height / 2 - 10), 20, 20);
    
    _ Offline
    _ Offline
    _AnsHUMAN_
    wrote on last edited by
    #3

    I don't hardcode the values. I get the center of the form and then try to draw the concentric circles

    You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

    D 1 Reply Last reply
    0
    • _ _AnsHUMAN_

      I don't hardcode the values. I get the center of the form and then try to draw the concentric circles

      You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

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

      So where is the problem then? Can you show some code and rephrase the problem?

      _ 1 Reply Last reply
      0
      • D dan sh

        So where is the problem then? Can you show some code and rephrase the problem?

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #5

        Of course! Based on the size of the form I have to draw concentric circles ( A user can resize the form). So the center of the circles should remain at the center of the form(assuming square shaped form) always. Also the circles should shrink/grow as the user resizes the form. I hope it's clearer now. In essence I have to create circles dynamically so that the center for two or more circles remain as the center of the form and the radius for each can be calculated in terms of a ratio.

        You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

        D 1 Reply Last reply
        0
        • _ _AnsHUMAN_

          Of course! Based on the size of the form I have to draw concentric circles ( A user can resize the form). So the center of the circles should remain at the center of the form(assuming square shaped form) always. Also the circles should shrink/grow as the user resizes the form. I hope it's clearer now. In essence I have to create circles dynamically so that the center for two or more circles remain as the center of the form and the radius for each can be calculated in terms of a ratio.

          You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

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

          The code I had posted does the same. What did you tried? Some code would be of help.

          _ 1 Reply Last reply
          0
          • D dan sh

            The code I had posted does the same. What did you tried? Some code would be of help.

            _ Offline
            _ Offline
            _AnsHUMAN_
            wrote on last edited by
            #7

            Your code only draws one circle at the center of the dialog. What if I want to draw two circles of different radius at the same center.

            You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

            D 1 Reply Last reply
            0
            • _ _AnsHUMAN_

              Your code only draws one circle at the center of the dialog. What if I want to draw two circles of different radius at the same center.

              You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

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

              Use the method two times. Was it this tough?

              _ 1 Reply Last reply
              0
              • D dan sh

                Use the method two times. Was it this tough?

                _ Offline
                _ Offline
                _AnsHUMAN_
                wrote on last edited by
                #9

                You didn't read the documentation of DrawEllipse probably. DrawEllipse - Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width. So we need to draw the bounding rectangle at the same center coordinates. Right? When I use your code it draws an ellipse starting at the coordinates(left top corner) you provide and with the width and height, and so the circles are not concentric. Anyways I have resolved the problem now. Thanks for your time and effort in helping me.

                You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                D 1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  You didn't read the documentation of DrawEllipse probably. DrawEllipse - Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width. So we need to draw the bounding rectangle at the same center coordinates. Right? When I use your code it draws an ellipse starting at the coordinates(left top corner) you provide and with the width and height, and so the circles are not concentric. Anyways I have resolved the problem now. Thanks for your time and effort in helping me.

                  You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

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

                  Somehow, these look concentric to me.

                  gx.Clear(this.BackColor);
                  gx = this.CreateGraphics();
                  gx.DrawEllipse(Pens.Red, (this.Width / 2 - 25), (this.Height / 2 - 25), 50, 50);
                  gx.DrawEllipse(Pens.Red, (this.Width / 2 - 50), (this.Height / 2 - 50), 100, 100);
                  gx.DrawEllipse(Pens.Red, (this.Width / 2 - 75), (this.Height / 2 - 75), 150, 150);
                  gx.DrawEllipse(Pens.Red, (this.Width / 2 - 100), (this.Height / 2 - 100), 200, 200);

                  _ 1 Reply Last reply
                  0
                  • D dan sh

                    Somehow, these look concentric to me.

                    gx.Clear(this.BackColor);
                    gx = this.CreateGraphics();
                    gx.DrawEllipse(Pens.Red, (this.Width / 2 - 25), (this.Height / 2 - 25), 50, 50);
                    gx.DrawEllipse(Pens.Red, (this.Width / 2 - 50), (this.Height / 2 - 50), 100, 100);
                    gx.DrawEllipse(Pens.Red, (this.Width / 2 - 75), (this.Height / 2 - 75), 150, 150);
                    gx.DrawEllipse(Pens.Red, (this.Width / 2 - 100), (this.Height / 2 - 100), 200, 200);

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #11

                    d@nish wrote:

                    gx.DrawEllipse(Pens.Red, (this.Width / 2 - 25

                    aren't you hardcoding the values for the rectangle. you are fixing the centers by subtracting some values based on the radius. isn't it? your circles won't get drawn with the same center when you increase or decrease forms size.

                    You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                    D M 2 Replies Last reply
                    0
                    • _ _AnsHUMAN_

                      d@nish wrote:

                      gx.DrawEllipse(Pens.Red, (this.Width / 2 - 25

                      aren't you hardcoding the values for the rectangle. you are fixing the centers by subtracting some values based on the radius. isn't it? your circles won't get drawn with the same center when you increase or decrease forms size.

                      You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

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

                      Only thing I have fixed is the radius of the circles, and that is because this is just some sample code. You need to handle the Resize event for the form as well and only then, no matter how you resize the form, the circles will be drawn with form's center as their center.

                      1 Reply Last reply
                      0
                      • _ _AnsHUMAN_

                        d@nish wrote:

                        gx.DrawEllipse(Pens.Red, (this.Width / 2 - 25

                        aren't you hardcoding the values for the rectangle. you are fixing the centers by subtracting some values based on the radius. isn't it? your circles won't get drawn with the same center when you increase or decrease forms size.

                        You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

                        M Offline
                        M Offline
                        musefan
                        wrote on last edited by
                        #13

                        Are you some sort of idiot?! How can you have fixed the problem when you cant even see the simple logic that is shown in the code provided by d@nish? If you put his code is the form's paint event then it will always draw in the centre of the form. And as for saying it only draws one circle - then no f%&^ing $^!t. you want two circles then you use DrawEllipse method two times! Guess how many times you call the method if you want three circles?!? 3 times!!!!!

                        Life goes very fast. Tomorrow, today is already yesterday.

                        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