Fix Graphics draw area size
I'm just starting to learn the GDI+ system for drawing lines, circles etc. I've created a component (scanner) that inherits a Panel to draw on (not sure if panel or picture box is best).

On the "Scanner" Im currently drawing a circle on it. the component can be added to a winform and using docking will resize when the winform resizes. At the moment I'm getting the size of the component to calculate the size of the circle but what I want to do is basically say no matter what size the component is the "canvas" is always 300 x 300 wide, so I can say the circle should be positioned at 25,25 with a size of 250x250.

As you might guess from the name "Scanner" I want to plot points on it, but these will be calculated from the center (150,150) location.

Below is the code I have that basically draws the circle. 

Many thanks for any help on this.

    public partial class Scanner : Panel
    {
    	public Scanner() {
    		InitializeComponent();
    		this.DoubleBuffered = true;
    	}
    
    	protected override void OnPaint(PaintEventArgs e) {
    		Graphics g = e.Graphics;
    		Draw(g);
    		base.OnPaint(e);
    	}
    	protected override void OnResize(EventArgs e) {
    		Graphics g = this.CreateGraphics();
    		Draw(g);
    		base.OnResize(e);
    	}
    
    	private void Draw(Graphics g) {
    		g.Clear(Color.Black);
    		g.PageUnit = GraphicsUnit.Pixel;
    		Pen green = new Pen(Color.Green);
    		Font fnt = new Font("Arial", 10);
    		SolidBrush sb = new SolidBrush(Color.Red);
    
    		int pos = (this.Width < this.Height ? this.Width : this.Height) / 2;
    		int size = (int)(pos * 1.9);
    		pos -= ((int)size / 2);
    		g.DrawEllipse(green, pos, pos, size, size);
    		g.DrawString(this.Width.ToString(), fnt, sb, new Point(0, 0));
    	}
    }

Fix Graphics draw area size
===

I'm just starting to learn the GDI+ system for drawing lines, circles etc. I've created a component (scanner) that inherits a Panel to draw on (not sure if panel or picture box is best).

On the "Scanner" Im currently drawing a circle on it. the component can be added to a winform and using docking will resize when the winform resizes. At the moment I'm getting the size of the component to calculate the size of the circle but what I want to do is basically say no matter what size the component is the "canvas" is always 300 x 300 wide, so I can say the circle should be positioned at 25,25 with a size of 250x250.

As you might guess from the name "Scanner" I want to plot points on it, but these will be calculated from the center (150,150) location.

Below is the code I have that basically draws the circle. 

Many thanks for any help on this.

    public partial class Scanner : Panel
    {
    	public Scanner() {
    		InitializeComponent();
    		this.DoubleBuffered = true;
    	}
    
    	protected override void OnPaint(PaintEventArgs e) {
    		Graphics g = e.Graphics;
    		Draw(g);
    		base.OnPaint(e);
    	}
    	protected override void OnResize(EventArgs e) {
    		Graphics g = this.CreateGraphics();
    		Draw(g);
    		base.OnResize(e);
    	}
    
    	private void Draw(Graphics g) {
    		g.Clear(Color.Black);
    		g.PageUnit = GraphicsUnit.Pixel;
    		Pen green = new Pen(Color.Green);
    		Font fnt = new Font("Arial", 10);
    		SolidBrush sb = new SolidBrush(Color.Red);
    
    		int pos = (this.Width < this.Height ? this.Width : this.Height) / 2;
    		int size = (int)(pos * 1.9);
    		pos -= ((int)size / 2);
    		g.DrawEllipse(green, pos, pos, size, size);
    		g.DrawString(this.Width.ToString(), fnt, sb, new Point(0, 0));
    	}
    }
