(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));

}

}

}

}





}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM