新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#畫線控件的開發(fā)應(yīng)用實例解析
C#畫線控件的應(yīng)用實例介紹之前我們要明白在C#中沒有畫線的控件,這里寫了一個,大家分享。共有兩個控件分別是畫橫線和畫豎線的,關(guān)于怎么畫斜線我還沒沒有,有興趣的可以做一個大家分享。

創(chuàng)新互聯(lián)公司的客戶來自各行各業(yè),為了共同目標(biāo),我們在工作上密切配合,從創(chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對我們的要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。專業(yè)領(lǐng)域包括成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、電商網(wǎng)站開發(fā)、微信營銷、系統(tǒng)平臺開發(fā)。
C#畫線控件之橫線
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- namespace Jiashi.WinControls
- {
- ///
- /// LineX 畫橫線控件
- ///
- public class LineX : System.Windows.Forms.UserControl
- {
- #region 屬性定義
- private System.Drawing.Color lineColor;
- private int lineWidth;
- ///
- /// 線的顏色屬性
- ///
- public System.Drawing.Color LineColor
- {
- set
- {
- this.lineColor=value;
- System.Windows.Forms.PaintEventArgs ep=
- new PaintEventArgs(this.CreateGraphics(),
- this.ClientRectangle);
- this.LineX_Paint(this,ep);
- }
- get{return this.lineColor;}
- }
- ///
- /// 線的粗細(xì)
- ///
- public int LineWidth
- {
- set
- {
- this.lineWidth=value;
- System.Windows.Forms.PaintEventArgs ep=
- new PaintEventArgs(this.CreateGraphics(),
- this.ClientRectangle);
- this.LineX_Paint(this,ep);
- }
- get{return this.lineWidth;}
- }
- #endregion
- private System.ComponentModel.Container components = null;
- ///
- /// 構(gòu)造函數(shù)初始顏色和線粗細(xì)
- ///
- public LineX()
- {
- InitializeComponent();
- this.lineColor=this.ForeColor;
- this.lineWidth=1;
- }
- ///
- /// 清理所有正在使用的資源。
- ///
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region 組件設(shè)計器生成的代碼
- ///
- /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器
- /// 修改此方法的內(nèi)容。
- ///
- private void InitializeComponent()
- {
- //
- // LineX
- //
- this.Name = "LineX";
- this.Resize += new System.EventHandler(this.LineX_Resize);
- this.Paint +=
- new System.Windows.Forms.PaintEventHandler(this.LineX_Paint);
- }
- #endregion
- private void LineX_Paint(object sender,
- System.Windows.Forms.PaintEventArgs e)
- {
- Graphics g=e.Graphics;
- Pen myPen = new Pen(this.lineColor);
- myPen.Width=this.lineWidth*2;
- this.Height=this.LineWidth;
- g.DrawLine(myPen,0,0,e.ClipRectangle.Right,0);
- }
- private void LineX_Resize(object sender, System.EventArgs e)
- {
- this.Height=this.lineWidth;
- }
- }
- }
C#畫線控件之豎線
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- namespace Jiashi.WinControls
- {
- ///
- /// LineY 畫豎線控件
- ///
- public class LineY : System.Windows.Forms.UserControl
- {
- #region 屬性定義
- private System.Drawing.Color lineColor;
- private int lineWidth;
- ///
- /// 線的顏色屬性
- ///
- public System.Drawing.Color LineColor
- {
- set
- {
- this.lineColor=value;
- System.Windows.Forms.PaintEventArgs ep=
- new PaintEventArgs(this.CreateGraphics(),
- this.ClientRectangle);
- this.LineY_Paint(this,ep);
- }
- get{return this.lineColor;}
- }
- ///
- /// 線的粗細(xì)
- ///
- public int LineWidth
- {
- set
- {
- this.lineWidth=value;
- System.Windows.Forms.PaintEventArgs ep=
- new PaintEventArgs(this.CreateGraphics(),
- this.ClientRectangle);
- this.LineY_Paint(this,ep);
- }
- get{return this.lineWidth;}
- }
- #endregion
- private System.ComponentModel.Container components = null;
- ///
- /// 構(gòu)造函數(shù)初始顏色和線粗細(xì)
- ///
- public LineY()
- {
- InitializeComponent();
- this.lineColor=this.ForeColor;
- this.lineWidth=1;
- }
- ///
- /// 清理所有正在使用的資源。
- ///
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region 組件設(shè)計器生成的代碼
- ///
- /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器
- /// 修改此方法的內(nèi)容。
- ///
- private void InitializeComponent()
- {
- //
- // LineY
- //
- this.Name = "LineY";
- this.Resize +=
- new System.EventHandler(this.LineY_Resize);
- this.Paint +=
- new System.Windows.Forms.PaintEventHandler(this.LineY_Paint);
- }
- #endregion
- private void LineY_Paint(
- object sender, System.Windows.Forms.PaintEventArgs e)
- {
- Graphics g=e.Graphics;
- Pen myPen = new Pen(this.lineColor);
- myPen.Width=this.lineWidth*2;
- this.Width=this.LineWidth;
- g.DrawLine(myPen,0,0,0,e.ClipRectangle.Bottom);
- }
- private void LineY_Resize(
- object sender, System.EventArgs e)
- {
- this.Width=this.lineWidth;
- }
- }
- }
C#畫線控件的開發(fā)就向你介紹到這里,希望對你了解和學(xué)習(xí)C#畫線控件有所幫助。
分享題目:C#畫線控件的開發(fā)應(yīng)用實例解析
文章路徑:http://www.dlmjj.cn/article/coojgdj.html


咨詢
建站咨詢
