As far as I can tell, the issue with your program is that you are calling CreateGraphics()
and drawing in the constructor (Form1()
). This might be problematic because the form is not yet fully initialized and displayed when Draw()
is called. Additionally, anything drawn using CreateGraphics()
will not persist if the form is refreshed (e.g., minimized and restored) because the drawing is not being done inside the OnPaint
event.
You might want to try overriding the OnPaint
method to ensure that the ellipse is drawn correctly and persists when the form is redrawn.
namespace Testing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (Pen pen = new Pen(Color.Red, 3))
{
e.Graphics.DrawEllipse(pen, 50, 50, 100, 100);
}
}
}
}
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin