i draw ellipse at runtime using following code.in that code i used graphics path for drawing(actually this is project requirement )and used widen method for graphics path.
but it gives runtime exception "out of memory".can i use this method in the case of ellipse?
while using widen method in the case of drawing rectangle at runtime, its working properly.
please solve this problem and give me some suggestion?
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Rectangle r;
bool isDown = false;
int initialX;
int initialY;
bool IsDrowing =true;
GraphicsPath gp1;
GraphicsPath gp2;
GraphicsPath gp3;
GraphicsPath gp;
Graphics g;
bool contained;
bool containedE;
bool containedC;
private void Form2_MouseDown(object sender, MouseEventArgs e)
{
isDown = true;
IsDrowing = true;
initialX = e.X;
initialY = e.Y;
}
private void Form2_MouseMove(object sender, MouseEventArgs e)
{
if (isDown == true)
{
int width = e.X - initialX, height = e.Y - initialY;
r = new Rectangle(Math.Min(e.X, initialX),
Math.Min(e.Y, initialY),
Math.Abs(e.X - initialX),
Math.Abs(e.Y - initialY));
this.Invalidate();
}
}
private void Form2_Paint(object sender, PaintEventArgs e)
{
g = this.CreateGraphics();
gp = new GraphicsPath();
Pen pen = new Pen(Color.Red);
gp.AddEllipse(r);
gp.Widen(pen);
pen.DashStyle = DashStyle.Dash;
if (IsDrowing)
{
g.DrawPath(pen, gp);
}
Rectangle rect=new Rectangle(100,200,100,90);
gp1 = new GraphicsPath();
gp1.AddRectangle(rect);
gp1.Widen(Pens.Red);
e.Graphics.DrawPath(Pens.Red,gp1);
Rectangle rect1 = new Rectangle(300, 200, 100, 90);
gp2 = new GraphicsPath();
gp2.AddEllipse(rect1);
gp2.Widen(Pens.Red);
e.Graphics.DrawPath(Pens.Red, gp2);
List<point> points = new List<point>();
points.Add(new Point(10, 10));
points.Add(new Point(100, 30));
points.Add(new Point(200, 80));
points.Add(new Point(500, 15));
gp3 = new GraphicsPath();
gp3.AddCurve(points.ToArray());
gp3.Widen(Pens.Blue);
e.Graphics.DrawPath(Pens.Blue, gp3);
Region r1 = new Region(gp1);
contained = r1.IsVisible(r);
Region r2 = new System.Drawing.Region(gp2);
containedE = r2.IsVisible(r);
Region r3 = new Region(gp3);
containedC = r3.IsVisible(r);
}
private void Form2_MouseUp(object sender, MouseEventArgs e)
{
IsDrowing = false;
this.Refresh();
isDown = false;
g=this.CreateGraphics();
if (contained)
{
g.DrawPath(Pens.Black, gp1);
}
if (containedE)
{
g.DrawPath(Pens.Black, gp2);
}
if (containedC)
{
g.DrawPath(Pens.Black, gp3);
}
}
}