标签:Pen C# Dispose 画线 System PEN using ClientRectangle
(C#)用PEN画线
//实现功能:用创建的PEN画线。 //(本例使用using创建Pen.其好处在于,在对象(pen)超出作用域时,using结构会自动调用Dispose(),将PEN删除。 // 若用其它方法创建绘图对象(一般都很费资源),则一定要显式调用Dispose() ,如: // " Graphics g = this.CreateGraphics(); // ........ // ........ // g.Dispose(); " //要点: // 创建Pen, Pen的颜色与粗细 获取客户区的height与Width using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace myDrawPanA { public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; using (Pen myPen = new Pen(Color.Red,1)) { if (ClientRectangle.Height/10>0) { for (int y=0; y< ClientRectangle.Height; y += ClientRectangle.Height/10) { g.DrawLine(myPen,new Point(0,0), new Point(ClientRectangle.Width,y)); } } } } } }HOLD ON! 发布了16 篇原创文章 · 获赞 219 · 访问量 25万+ 私信 关注
标签:Pen,C#,Dispose,画线,System,PEN,using,ClientRectangle 来源: https://blog.csdn.net/cxu123321/article/details/104617455
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。