View code
Public void drawword_first (Object sender, painteventargs E)
{
Graphics GD = E. graphics;
// G. smoothingmode = smoothingmode. antialias;
Graphicspath stringpath = new graphicspath ();
Charinfo chars = new charinfo ();
String drawwords = chars. getchars ();
Stringpath. addstring (chars. getchars (), new fontfamily (" _ gb2312"), 0, 96, new point (0, 0), stringformat. genericdefault );
GD. drawpath (new pen (brushes. Blue), stringpath );
GD. Dispose ();
}
View code
public void OnPaint_drawTian(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
this.tianHeight = 200;
this.tianWidth = 200;
this.tianLeftTop = new Point(0,0);
this.tianRightTop = new Point(this.tianWidth,0);
this.tianLeftBottom = new Point(0,this.tianHeight);
this.tianRightBottom = new Point(this.tianWidth,this.tianHeight);
this.tianTopCenter = new Point(this.tianWidth/2,0);
this.tianBottomCenter=new Point(this.tianWidth/2,this.tianHeight);
this.tianLeftCenter = new Point(0,this.tianHeight/2);
this.tianRightCenter = new Point(this.tianWidth,this.tianHeight/2);
this.tianRectangle = new Rectangle(this.tianLeftTop,new Size(this.tianWidth,this.tianHeight));
this.tianPen=new Pen(Brushes.Red,2);
this.tianPen.DashStyle = DashStyle.DashDot;
g.DrawLine(this.tianPen, this.tianRectangle.Left, this.tianRectangle.Top, this.tianRectangle.Left + this.tianWidth, this.tianRectangle.Bottom);
g.DrawLine(this.tianPen,this.tianRightTop,this.tianLeftBottom);
g.DrawLine(this.tianPen,this.tianLeftCenter,this.tianRightCenter);
g.DrawLine(this.tianPen,this.tianTopCenter,this.tianBottomCenter);
this.tianPen.DashStyle = DashStyle.Solid;
g.DrawRectangle(this.tianPen,this.tianRectangle);
//g.Dispose();
}
When the memory is released, an invalid parameter exception is reported. After thinking, it seems that after the first g object is released, the second painting will become a problem. Therefore, the correct syntax should be as follows:
Public void onpaint_drawtian (Object sender, painteventargs e ){...// G. Dispose ();}
Public void drawword_first (Object sender, painteventargs e) {... G. Dispose ();}
Excuse me, no, the two functions are called next to each other (just comment out the first dispose Statement)
In additionThe order of memory release should be the opposite of that used...
Bytes -------------------------------------------------------------------------------------------------------------------
Dispose has nothing to do with close. They share a similar convention.
The Convention of dispose is that this method will release all resources occupied by the instance and destroy itself.
Note that the dispose convention is to release all resources and destroy itself. That is to say, in most cases, instances that are dispose should not be used again.
If a class has both the dispose and close methods, the close method is called in general.
Close is only closed. You can open it again if you have not released the resources.
Dispose destroys an object and will no longer exist.
Close is to suspend business for rectification, dispose is to blow up;
Close is closed, dispose is broke.