`
v5qqcom
  • 浏览: 1289399 次
文章分类
社区版块
存档分类
最新评论

C#画线控件的开发应用实例解析

 
阅读更多

C#画线控件的应用实例介绍之前我们要明白在C#中没有画线的控件,这里写了一个,大家分享。共有两个控件分别是画横线和画竖线的,关于怎么画斜线有兴趣的可以做一个大家分享。

C#画线控件之横线

usingSystem;

usingSystem.Collections;

usingSystem.ComponentModel;

usingSystem.Drawing;

usingSystem.Data;

usingSystem.Windows.Forms;

namespaceJiashi.WinControls

{

///

///LineX画横线控件

///

publicclassLineX:System.Windows.Forms.UserControl

{

#region属性定义

privateSystem.Drawing.ColorlineColor;

privateintlineWidth;

///

///线的颜色属性

///

publicSystem.Drawing.ColorLineColor

{

set

{

this.lineColor=value;

System.Windows.Forms.PaintEventArgsep=

newPaintEventArgs(this.CreateGraphics(),

this.ClientRectangle);

this.LineX_Paint(this,ep);

}

get{returnthis.lineColor;}

}

///

///线的粗细

///

publicintLineWidth

{

set

{

this.lineWidth=value;

System.Windows.Forms.PaintEventArgsep=

newPaintEventArgs(this.CreateGraphics(),

this.ClientRectangle);

this.LineX_Paint(this,ep);

}

get{returnthis.lineWidth;}

}

#endregion

privateSystem.ComponentModel.Containercomponents=null;

///

///构造函数初始颜色和线粗细

///

publicLineX()

{

InitializeComponent();

this.lineColor=this.ForeColor;

this.lineWidth=1;

}

///

///清理所有正在使用的资源。

///

protectedoverridevoidDispose(booldisposing)

{

if(disposing)

{

if(components!=null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

#region组件设计器生成的代码

///

///设计器支持所需的方法-不要使用代码编辑器

///修改此方法的内容。

///

privatevoidInitializeComponent()

{

//

//LineX

//

this.Name="LineX";

this.Resize+=newSystem.EventHandler(this.LineX_Resize);

this.Paint+=

newSystem.Windows.Forms.PaintEventHandler(this.LineX_Paint);

}

#endregion

privatevoidLineX_Paint(objectsender,

System.Windows.Forms.PaintEventArgse)

{

Graphicsg=e.Graphics;

PenmyPen=newPen(this.lineColor);

myPen.Width=this.lineWidth*2;

this.Height=this.LineWidth;

g.DrawLine(myPen,0,0,e.ClipRectangle.Right,0);

}

privatevoidLineX_Resize(objectsender,System.EventArgse)

{

this.Height=this.lineWidth;

}

}

}

C#画线控件之竖线

usingSystem;

usingSystem.Collections;

usingSystem.ComponentModel;

usingSystem.Drawing;

usingSystem.Data;

usingSystem.Windows.Forms;

namespaceJiashi.WinControls

{

///

///LineY画竖线控件

///

publicclassLineY:System.Windows.Forms.UserControl

{

#region属性定义

privateSystem.Drawing.ColorlineColor;

privateintlineWidth;

///

///线的颜色属性

///

publicSystem.Drawing.ColorLineColor

{

set

{

this.lineColor=value;

System.Windows.Forms.PaintEventArgsep=

newPaintEventArgs(this.CreateGraphics(),

this.ClientRectangle);

this.LineY_Paint(this,ep);

}

get{returnthis.lineColor;}

}

///

///线的粗细

///

publicintLineWidth

{

set

{

this.lineWidth=value;

System.Windows.Forms.PaintEventArgsep=

newPaintEventArgs(this.CreateGraphics(),

this.ClientRectangle);

this.LineY_Paint(this,ep);

}

get{returnthis.lineWidth;}

}

#endregion

privateSystem.ComponentModel.Containercomponents=null;

///

///构造函数初始颜色和线粗细

///

publicLineY()

{

InitializeComponent();

this.lineColor=this.ForeColor;

this.lineWidth=1;

}

///

///清理所有正在使用的资源。

///

protectedoverridevoidDispose(booldisposing)

{

if(disposing)

{

if(components!=null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

#region组件设计器生成的代码

///

///设计器支持所需的方法-不要使用代码编辑器

///修改此方法的内容。

///

privatevoidInitializeComponent()

{

//

//LineY

//

this.Name="LineY";

this.Resize+=

newSystem.EventHandler(this.LineY_Resize);

this.Paint+=

newSystem.Windows.Forms.PaintEventHandler(this.LineY_Paint);

}

#endregion

privatevoidLineY_Paint(

objectsender,System.Windows.Forms.PaintEventArgse)

{

Graphicsg=e.Graphics;

PenmyPen=newPen(this.lineColor);

myPen.Width=this.lineWidth*2;

this.Width=this.LineWidth;

g.DrawLine(myPen,0,0,0,e.ClipRectangle.Bottom);

}

privatevoidLineY_Resize(

objectsender,System.EventArgse)

{

this.Width=this.lineWidth;

}

}

}

C#画线控件的开发就向你介绍到这里,希望对你了解和学习C#画线控件有所帮助。

分享到:
评论

相关推荐

    c# 使用Graphics画线实例

    c# 画线实例 Graphics入门实用的例子

    明日科技C#开发入门及项目实战

    第1章 c#语言及其开发环境 实例001 根据需要创建所需解决方案 实例002 统一窗体中控件的字体设置 实例003 设置程序代码行号 实例004 通过“格式”菜单布局窗体 实例005 为项目添加dll文件引用 实例006 为项目添加已...

    Visual+C#+2008程序设计经典案例设计与实现.rar

    Visual+C#+2008程序设计经典案例设计与实现 第1章 Visual C#2008与窗体界面 案例1 飘动动画窗体 案例2 透明动画窗体 案例3 利用API函数实现动画窗体 案例4 闪烁动画窗体 案例5 滚动字幕动画窗体 案例6 超女卡通...

    C#程序开发范例宝典(第2版).part08

    实例089 MaskedTextBox控件的简单应用 128 实例090 制作日历计划任务 130 实例091 在ProgressBar控件中显示进度百分比 132 实例092 在NumericUpDown控件中显示当前系统日期 133 2.10 控件技术 134 实例093 程序...

    Visual C# 2008程序设计经典案例设计与实现

    第9章 Visual C#2008算法及控件的应用 案例1 利用冒泡算法实现从小到大排序 案例2 利用希尔算法实现从大到小排序 案例3 判断主机Ⅳ合法性算法 案例4 欧几里德最大公因子算法 案例5 字符串的加密算法 案例6 ...

    C#程序开发范例宝典(第2版).part12

    实例089 MaskedTextBox控件的简单应用 128 实例090 制作日历计划任务 130 实例091 在ProgressBar控件中显示进度百分比 132 实例092 在NumericUpDown控件中显示当前系统日期 133 2.10 控件技术 134 实例093 程序...

    Diagram.NET思维导图与流程图绘制工具(C#)

    1.Diagram.NET是一个简单实用的绘图工具,可以绘制指定形状的...6.连接线可以选择折线还是直线连接。 7.可以对工作区进行放大缩小等操作。 8.每个节点都有详细的属性设置,使用的是.NET属性编辑器控件,修改非常方便。

    C#设计经典案例设计与实现

    案例1 抛物线动画效果 案例2 图像滚动动画效果 案例3 飞舞的雪花 案例4 电子时钟 案例5 Flash动画播放器 案例6 AvI动画播放器 案例7 GⅣ动画播放器 案例8 MP3音乐播放器 案例9 肥皂泡泡屏幕保护程序 案例1O 图像随机...

    C# 源码 C#2008经典案例

    案例1 抛物线动画效果 案例2 图像滚动动画效果 案例3 飞舞的雪花 案例4 电子时钟 案例5 Flash动画播放器 案例6 AvI动画播放器 案例7 GⅣ动画播放器 案例8 MP3音乐播放器 案例9 肥皂泡泡屏幕保护程序 案例1O 图像随机...

    C#画流程图全部可任意玩耍

    窗体里全部东西都可以拖动,改变大小,包括线头 点击节点1然后再点击节点2 自动连线 也可以自助连线 有方块 有原型 有Button 很多选择

    C#程序开发范例宝典(第2版).part02

    实例089 MaskedTextBox控件的简单应用 128 实例090 制作日历计划任务 130 实例091 在ProgressBar控件中显示进度百分比 132 实例092 在NumericUpDown控件中显示当前系统日期 133 2.10 控件技术 134 实例093 程序...

    C#使用chart实现折线图和曲线图显示

    C#实现随机数的折现图。使用chart控件实现折线图和波形图的切换功能, 单条曲线显示案例,可以参考

    C#程序开发范例宝典(第2版).part13

    实例089 MaskedTextBox控件的简单应用 128 实例090 制作日历计划任务 130 实例091 在ProgressBar控件中显示进度百分比 132 实例092 在NumericUpDown控件中显示当前系统日期 133 2.10 控件技术 134 实例093 程序...

Global site tag (gtag.js) - Google Analytics