The code below create one circle inside the windows form.
This code compiled without any errors. But it didn’t draw the ellipse?! Why?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication1
{
public class Task1 : Form1
{
public void FillEllipseInt(PaintEventArgs e)
{
SolidBrush redBrush = new SolidBrush(Color.Red);
int x = 100;
int y = 100;
int width = 200;
int height = 100;
e.Graphics.FillEllipse(redBrush, x, y, width, height);
}
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
You need to attach the
Paintevent of the form and from that call yourFillEllipseIntmethod. Also, you need to changeApplication.Run(new Form1());toApplication.Run(new Task1());as (at least in the code you’ve shown) there’s notForm1class. This is also why I think thatTask1should inherit fromFormand notForm1.