溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C#畫線控件的方法

發(fā)布時間:2021-06-16 14:40:01 來源:億速云 閱讀:922 作者:chen 欄目:編程語言

這篇文章主要介紹“C#畫線控件的方法”,在日常操作中,相信很多人在C#畫線控件的方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C#畫線控件的方法”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

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

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;}  }  ///   /// 線的粗細  ///   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ù)初始顏色和線粗細  ///   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;}  }  ///   /// 線的粗細  ///   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ù)初始顏色和線粗細  ///   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;  }   }  }

到此,關(guān)于“C#畫線控件的方法”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI