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

}

}

}

}





}

}

转载于:https://www.cnblogs.com/Holmes-Jin/archive/2012/01/30/2331871.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值