加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

(C#)用PEN画线

(2011-11-17 16:25:46)
标签:

pen

画线

csharp

分类: C#笔记

(C#)用PEN画线myDrawPenA

 

//实现功能:用创建的PEN画线。

//(本例使用using创建Pen.其好处在于,在对象(pen)超出作用域时,using结构会自动调用Dispose(),PEN删除。

// 若用其它方法创建绘图对象(一般都很费资源),则一定要显式调用Dispose() ,:

// " Graphics g = this.CreateGraphics();

//   ........

//   ........

//  g.Dispose(); "

//要点:

//   创建Pen, Pen的颜色与粗细  获取客户区的heightWidth

 

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

                    }

                }

            }

        }

 

 

    }

}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有