2 Replies - 1272 Views - Last Post: 05 May 2010 - 10:37 AM Rate Topic: -----

#1 Dean90   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 01-February 10

Draw circle issue when drawing near corners.

Posted 29 April 2010 - 09:17 AM

Hi all, Let me first give an example of what I am doing and then explain my issue.

using (Graphics Draw = Graphics.FromImage(NewPicture))
{
UInt16 Diameter = (UInt16)(Radius * 2);
UInt16 StartX = (UInt16)(XVal - Radius);
UInt16 StartY = (UInt16)(YVal - Radius);
Draw.DrawEllipse(Pens.Red, StartX, StartY, Diameter, Diameter);
}



The mittle point of the circle is (XVal,YVal).
Now if the mittle point of the circle would be too close to a corner in the picturebox then StartX/StartY could end up outside the picturebox. And then this would never draw a circle. I want it to draw a circle even if it turns up as a half circle or 1/3rd of it.

Does anyone have any ideas on how to get that to work?

Thanks for any help I can get!

Is This A Good Question/Topic? 0
  • +

Replies To: Draw circle issue when drawing near corners.

#2 lbray785   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 11
  • Joined: 30-March 10

Re: Draw circle issue when drawing near corners.

Posted 30 April 2010 - 10:18 PM

Here is an example of drawing ellipses in a picture box that I did during my programming class. I did not fully understand the question but I hope this helps with the problem.

 public partial class MainForm : Form
    {
        private List<Target> _circle = new List<Target>();

        public MainForm()
        {
            InitializeComponent();
        }

        private void pbxBullsEye_Paint(object sender, PaintEventArgs e)
        {
            _circle.Add(new Target(100, 100, 20, Color.Black));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(90, 90, 40, Color.White));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(80, 80, 60, Color.Black));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(70, 70, 80, Color.White));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(60, 60, 100, Color.Black));
            pbxBullsEye.Invalidate();
            
            foreach (Target circle in _circle)
            {
                circle.Draw(e.Graphics);
            }
        }
    }

    public class Target
    {
        private Color _color;
        private int _size;
        private int _x;
        private int _y;

        public Target(int x, int y, int size, Color color)
        {
            _x = x;
            _y = y;
            _size = size;
            _color = color;
        }

        public void Draw(Graphics graphics)
        {
            if (graphics != null)
            {
                graphics.DrawEllipse(new Pen(_color), _x, _y, _size, _size);
            }
        }
    }
}

Was This Post Helpful? 0
  • +
  • -

#3 Dean90   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 01-February 10

Re: Draw circle issue when drawing near corners.

Posted 05 May 2010 - 10:37 AM

View Postlbray785, on 30 April 2010 - 09:18 PM, said:

Here is an example of drawing ellipses in a picture box that I did during my programming class. I did not fully understand the question but I hope this helps with the problem.

 public partial class MainForm : Form
    {
        private List<Target> _circle = new List<Target>();

        public MainForm()
        {
            InitializeComponent();
        }

        private void pbxBullsEye_Paint(object sender, PaintEventArgs e)
        {
            _circle.Add(new Target(100, 100, 20, Color.Black));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(90, 90, 40, Color.White));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(80, 80, 60, Color.Black));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(70, 70, 80, Color.White));
            pbxBullsEye.Invalidate();
            _circle.Add(new Target(60, 60, 100, Color.Black));
            pbxBullsEye.Invalidate();
            
            foreach (Target circle in _circle)
            {
                circle.Draw(e.Graphics);
            }
        }
    }

    public class Target
    {
        private Color _color;
        private int _size;
        private int _x;
        private int _y;

        public Target(int x, int y, int size, Color color)
        {
            _x = x;
            _y = y;
            _size = size;
            _color = color;
        }

        public void Draw(Graphics graphics)
        {
            if (graphics != null)
            {
                graphics.DrawEllipse(new Pen(_color), _x, _y, _size, _size);
            }
        }
    }
}


Yeah that wasn't my question sorry. So I'm bumping this, does anyone have any ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1