自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#畫線控件的開發(fā)應(yīng)用實例解析

開發(fā) 后端
C#畫線控件是什么呢?是如何使用的呢?那么這里向你介紹了C#畫線控件開發(fā)中的兩種,分別是橫線和豎線的實現(xiàn),希望對你了解和學(xué)習(xí)C#畫線控件有所幫助。

C#畫線控件的應(yīng)用實例介紹之前我們要明白在C#中沒有畫線的控件,這里寫了一個,大家分享。共有兩個控件分別是畫橫線和畫豎線的,關(guān)于怎么畫斜線我還沒沒有,有興趣的可以做一個大家分享。

C#畫線控件之橫線

  1. using System;  
  2. using System.Collections;  
  3. using System.ComponentModel;  
  4. using System.Drawing;  
  5. using System.Data;  
  6. using System.Windows.Forms;  
  7.  
  8. namespace Jiashi.WinControls  
  9. {  
  10.  ///   
  11.  /// LineX 畫橫線控件  
  12.  ///   
  13.  public class LineX : System.Windows.Forms.UserControl  
  14.  {  
  15.  
  16. #region 屬性定義  
  17. private System.Drawing.Color lineColor;  
  18. private int lineWidth;  
  19. ///   
  20. /// 線的顏色屬性  
  21. ///   
  22. public System.Drawing.Color LineColor  
  23. {  
  24.  set 
  25.  {  
  26. this.lineColor=value;  
  27. System.Windows.Forms.PaintEventArgs ep=  
  28. new PaintEventArgs(this.CreateGraphics(),  
  29. this.ClientRectangle);  
  30. this.LineX_Paint(this,ep);  
  31.  }  
  32.  get{return this.lineColor;}  
  33. }  
  34. ///   
  35. /// 線的粗細(xì)  
  36. ///   
  37. public int LineWidth  
  38. {  
  39.  set 
  40.  {  
  41. this.lineWidth=value;  
  42. System.Windows.Forms.PaintEventArgs ep=  
  43. new PaintEventArgs(this.CreateGraphics(),  
  44. this.ClientRectangle);  
  45. this.LineX_Paint(this,ep);  
  46.  }  
  47.  get{return this.lineWidth;}  
  48. }  
  49. #endregion  
  50. private System.ComponentModel.Container components = null;  
  51.  
  52. ///   
  53. /// 構(gòu)造函數(shù)初始顏色和線粗細(xì)  
  54. ///   
  55. public LineX()  
  56. {  
  57.  InitializeComponent();  
  58.  this.lineColor=this.ForeColor;  
  59.  this.lineWidth=1;  
  60.  
  61. }  
  62.  
  63. ///   
  64. /// 清理所有正在使用的資源。  
  65. ///   
  66. protected override void Dispose( bool disposing )  
  67. {  
  68.  if( disposing )  
  69.  {  
  70. if(components != null)  
  71. {  
  72.  components.Dispose();  
  73. }  
  74.  }  
  75.  base.Dispose( disposing );  
  76. }  
  77.  
  78. #region 組件設(shè)計器生成的代碼  
  79. ///   
  80. /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器   
  81. /// 修改此方法的內(nèi)容。  
  82. ///   
  83. private void InitializeComponent()  
  84. {  
  85.  //   
  86.  // LineX  
  87.  //   
  88.  this.Name = "LineX";  
  89.  this.Resize += new System.EventHandler(this.LineX_Resize);  
  90.  this.Paint +=   
  91. new System.Windows.Forms.PaintEventHandler(this.LineX_Paint);  
  92.  
  93. }  
  94. #endregion  
  95.  
  96. private void LineX_Paint(object sender,  
  97.  System.Windows.Forms.PaintEventArgs e)  
  98. {  
  99.  Graphics g=e.Graphics;  
  100.  Pen myPen = new Pen(this.lineColor);  
  101.  myPen.Width=this.lineWidth*2;  
  102.  this.Height=this.LineWidth;  
  103.  g.DrawLine(myPen,0,0,e.ClipRectangle.Right,0);  
  104. }  
  105.  
  106. private void LineX_Resize(object sender, System.EventArgs e)  
  107. {  
  108.  this.Height=this.lineWidth;  
  109. }  
  110.  }  
  111. }  

C#畫線控件之豎線

  1. using System;  
  2. using System.Collections;  
  3. using System.ComponentModel;  
  4. using System.Drawing;  
  5. using System.Data;  
  6. using System.Windows.Forms;  
  7.  
  8. namespace Jiashi.WinControls  
  9. {  
  10.  ///   
  11.  /// LineY 畫豎線控件  
  12.  ///   
  13.  public class LineY : System.Windows.Forms.UserControl  
  14.  {  
  15.  
  16. #region 屬性定義  
  17. private System.Drawing.Color lineColor;  
  18. private int lineWidth;  
  19. ///   
  20. /// 線的顏色屬性  
  21. ///   
  22. public System.Drawing.Color LineColor  
  23. {  
  24.  set 
  25.  {  
  26. this.lineColor=value;  
  27. System.Windows.Forms.PaintEventArgs ep=  
  28. new PaintEventArgs(this.CreateGraphics(),  
  29. this.ClientRectangle);  
  30. this.LineY_Paint(this,ep);  
  31.  }  
  32.  get{return this.lineColor;}  
  33. }  
  34. ///   
  35. /// 線的粗細(xì)  
  36. ///   
  37. public int LineWidth  
  38. {  
  39.  set 
  40.  {  
  41. this.lineWidth=value;  
  42. System.Windows.Forms.PaintEventArgs ep=  
  43. new PaintEventArgs(this.CreateGraphics(),  
  44. this.ClientRectangle);  
  45. this.LineY_Paint(this,ep);  
  46.  }  
  47.  get{return this.lineWidth;}  
  48. }  
  49. #endregion  
  50. private System.ComponentModel.Container components = null;  
  51.  
  52. ///   
  53. /// 構(gòu)造函數(shù)初始顏色和線粗細(xì)  
  54. ///   
  55. public LineY()  
  56. {  
  57.  InitializeComponent();  
  58.  this.lineColor=this.ForeColor;  
  59.  this.lineWidth=1;  
  60.  
  61. }  
  62.  
  63. ///   
  64. /// 清理所有正在使用的資源。  
  65. ///   
  66. protected override void Dispose( bool disposing )  
  67. {  
  68.  if( disposing )  
  69.  {  
  70. if(components != null)  
  71. {  
  72.  components.Dispose();  
  73. }  
  74.  }  
  75.  base.Dispose( disposing );  
  76. }  
  77.  
  78. #region 組件設(shè)計器生成的代碼  
  79. ///   
  80. /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器   
  81. /// 修改此方法的內(nèi)容。  
  82. ///   
  83. private void InitializeComponent()  
  84. {  
  85.  //   
  86.  // LineY  
  87.  //   
  88.  this.Name = "LineY";  
  89.  this.Resize +=   
  90. new System.EventHandler(this.LineY_Resize);  
  91.  this.Paint +=   
  92. new System.Windows.Forms.PaintEventHandler(this.LineY_Paint);  
  93.  
  94. }  
  95. #endregion  
  96.  
  97. private void LineY_Paint(  
  98. object sender, System.Windows.Forms.PaintEventArgs e)  
  99. {  
  100.  Graphics g=e.Graphics;  
  101.  Pen myPen = new Pen(this.lineColor);  
  102.  myPen.Width=this.lineWidth*2;  
  103.  this.Width=this.LineWidth;  
  104.  g.DrawLine(myPen,0,0,0,e.ClipRectangle.Bottom);  
  105. }  
  106.  
  107. private void LineY_Resize(  
  108. object sender, System.EventArgs e)  
  109. {  
  110.  this.Width=this.lineWidth;  
  111. }  
  112.  }  
  113. }  

C#畫線控件的開發(fā)就向你介紹到這里,希望對你了解和學(xué)習(xí)C#畫線控件有所幫助。

【編輯推薦】

  1. C#單元測試概念及作用的淺析
  2. C#單元測試使用的必要性的淺析
  3. C#單元測試的運行淺析
  4. 常見的C#單元測試工具介紹
  5. C#畫直線實現(xiàn)實例解析
責(zé)任編輯:仲衡 來源: cnblogs
相關(guān)推薦

2009-09-03 09:16:35

C#遞歸函數(shù)

2009-09-03 15:43:21

C#時間計算

2009-08-28 11:09:35

C#數(shù)組初始化

2009-08-26 13:36:33

C#打印控件

2009-09-09 14:40:15

C# XML解析

2009-08-31 17:16:12

C#實現(xiàn)接口

2009-08-27 17:40:21

C#接口的作用

2009-08-31 17:30:10

C#接口的作用

2009-09-09 13:57:28

C# XML解析

2009-08-18 10:47:40

C#枚舉類型

2009-08-26 12:14:44

C#打印設(shè)置

2009-09-07 06:31:32

C#窗體移動

2009-08-19 16:09:15

C#操作Access

2009-08-31 18:17:32

C#接口編程

2009-09-02 19:12:37

C#遞歸

2009-08-24 10:10:09

C#復(fù)合控件

2009-08-28 15:37:22

C#線程類的定義

2009-08-17 17:49:20

C# 枚舉

2009-09-11 12:31:52

C#實例詳解TypeConvert

2009-08-28 12:31:06

C#靜態(tài)方法
點贊
收藏

51CTO技術(shù)棧公眾號