how to Draw an ellipse using c#

W

weird0

I wanted to draw an ellipse using c# with System.Drawing.Graphics. I
tried out several tutorials and none of them worked and there seems to
be something missing. One did execute without any errors but it did
not render an ellipse on the form.

I want to create an ellipse with just a new project with one form
default, that is Form1. I want the draw ellipse function to be in some
other class,say Shapes( user-defined) and then call it in the form1
class. How can i do this successgully? I tried hell lot of stuff.

Need help
Amir Diwan
 
M

Marc Gravell

Well, drawing an ellipse is easy - but you need to be a bit clearer on
your context; perhaps post what isn't working? But following works:

static class Program {
static void Main() {
Application.EnableVisualStyles();
Application.Run(new MyForm());
}
}
class MyForm : Form {
protected override void OnResize(EventArgs e) {
base.OnResize(e);
Invalidate();
}
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
e.Graphics.DrawEllipse(SystemPens.ControlText,
ClientRectangle);
}
}

Marc
 
B

Bob Powell [MVP]

You may be interested in the GDI+ FAQ and the Beginners Guide to GDI+ which
can be found on my site.

http://bobpowell.net/beginnersgdi.htm

For the GDI+ FAQ see the link in my signature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top