欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 開發(fā)step步驟條控件詳解

 更新時(shí)間:2017年03月05日 10:17:02   作者:JackWang-CUMT  
本篇文章主要介紹了用C#來(lái)實(shí)現(xiàn)一個(gè)step控件的方法步驟,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

現(xiàn)在很多的javascript控件,非常的不錯(cuò),其中step就是一個(gè),如下圖所示:

那么如何用C#來(lái)實(shí)現(xiàn)一個(gè)step控件呢?

先定義一個(gè)StepEntity類來(lái)存儲(chǔ)步驟條節(jié)點(diǎn)的信息:

public class StepEntity
 {
  public string Id { get; set; }
  public string StepName { get; set; }
  public int StepOrder { get; set; }
  public eumStepState StepState { get; set; }
  public string StepDesc { get; set; }
  public object StepTag { get; set; }
  //public Image StepCompletedImage { get; set; }
  //public Image StepDoingImage { get; set; }
  public StepEntity(string id,string stepname,int steporder,string stepdesc, eumStepState stepstate,object tag)
  {
   this.Id = id;
   this.StepName = stepname;
   this.StepOrder = steporder;
   this.StepDesc = stepdesc;
   this.StepTag = tag;
   this.StepState = stepstate;
  }
 }

定義一個(gè)名為StepViewer 的用戶控件。

public partial class StepViewer : UserControl
 {
  public StepViewer()
  {
   InitializeComponent();
   this.Height = 68;
  }
}

在StepViewer 的用戶控件中定義一個(gè)ListDataSource的屬性,如下:

private List<StepEntity> _dataSourceList = null;
  [Browsable(true), Category("StepViewer")]
  public List<StepEntity> ListDataSource
  {
   get
   {
    return _dataSourceList;
   }
   set
   {
    if (_dataSourceList != value)
    {
     _dataSourceList = value;
     Invalidate();
    }
   }
  }

在此控件的paint方法中,進(jìn)行步驟條的繪制:

private void StepViewer_Paint(object sender, PaintEventArgs e)
  {
   if(this.ListDataSource!=null)
   {
    int CenterY = this.Height / 2;
    int index = 1;
    int count = ListDataSource.Count;
    int lineWidth = 120;
    int StepNodeWH = 28;
    //this.Width = 32 * count + lineWidth * (count - 1) + 6+300;
    //defalut pen & brush
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    Brush brush = new SolidBrush(_Gray);
    Pen p = new Pen(brush, 1f);
    Brush brushNode = new SolidBrush(_DarkGray);
    Pen penNode = new Pen(brushNode, 1f);
    Brush brushNodeCompleted = new SolidBrush(_Blue);
    Pen penNodeCompleted = new Pen(brushNodeCompleted, 1f);
    int initX = 6;
    //string
    Font nFont = new Font("微軟雅黑", 12);
    Font stepFont = new Font("微軟雅黑", 11,FontStyle.Bold);
    int NodeNameWidth = 0;
    foreach (var item in ListDataSource)
    {
     //round
     Rectangle rec = new Rectangle(initX, CenterY - StepNodeWH / 2, StepNodeWH, StepNodeWH);
     if (CurrentStep == item.StepOrder)
     {
      if (item.StepState == eumStepState.OutTime)
      {
       e.Graphics.DrawEllipse(new Pen(_Red,1f), rec);
       e.Graphics.FillEllipse(new SolidBrush(_Red), rec);
      }
      else
      {
       e.Graphics.DrawEllipse(penNodeCompleted, rec);
       e.Graphics.FillEllipse(brushNodeCompleted, rec);
      }
      //白色字體
      SizeF fTitle = e.Graphics.MeasureString(index.ToString(), stepFont);
      Point pTitle = new Point(initX + StepNodeWH / 2 - (int)Math.Round(fTitle.Width) / 2, CenterY - (int)Math.Round(fTitle.Height / 2));
      e.Graphics.DrawString(index.ToString(), stepFont, Brushes.White, pTitle);
      //nodeName
      SizeF sNode = e.Graphics.MeasureString(item.StepName, nFont);
      Point pNode = new Point(initX + StepNodeWH, CenterY - (int)Math.Round(sNode.Height / 2) + 2);
      e.Graphics.DrawString(item.StepName,new Font( nFont,FontStyle.Bold), brushNode, pNode);
      NodeNameWidth = (int)Math.Round(sNode.Width);
      if (index < count)
      {
       e.Graphics.DrawLine(p, initX + StepNodeWH + NodeNameWidth, CenterY, initX + StepNodeWH + NodeNameWidth + lineWidth, CenterY);
      }
     }
     else if (item.StepOrder < CurrentStep)
     {
      //completed
      e.Graphics.DrawEllipse(penNodeCompleted, rec);
      //image
      RectangleF recRF = new RectangleF(rec.X + 6, rec.Y + 6, rec.Width - 12, rec.Height - 12);
      e.Graphics.DrawImage(ControlsResource.check_lightblue, recRF);
      //nodeName
      SizeF sNode = e.Graphics.MeasureString(item.StepName, nFont);
      Point pNode = new Point(initX + StepNodeWH, CenterY - (int)Math.Round(sNode.Height / 2) + 2);
      e.Graphics.DrawString(item.StepName, nFont, brushNode, pNode);
      NodeNameWidth = (int)Math.Round(sNode.Width);
      if (index < count)
      {
       e.Graphics.DrawLine(penNodeCompleted, initX + StepNodeWH + NodeNameWidth, CenterY, initX + StepNodeWH + NodeNameWidth + lineWidth, CenterY);
      }
     }
     else
     {
      e.Graphics.DrawEllipse(p, rec);
      //
      SizeF fTitle = e.Graphics.MeasureString(index.ToString(), stepFont);
      Point pTitle = new Point(initX + StepNodeWH / 2 - (int)Math.Round(fTitle.Width) / 2, CenterY - (int)Math.Round(fTitle.Height / 2));
      e.Graphics.DrawString(index.ToString(), stepFont, brush, pTitle);
      //nodeName
      SizeF sNode = e.Graphics.MeasureString(item.StepName, nFont);
      Point pNode = new Point(initX + StepNodeWH, CenterY - (int)Math.Round(sNode.Height / 2) + 2);
      e.Graphics.DrawString(item.StepName, nFont, brushNode, pNode);
      NodeNameWidth = (int)Math.Round(sNode.Width);
      if (index < count)
      {
       //line
       e.Graphics.DrawLine(p, initX + StepNodeWH + NodeNameWidth, CenterY, initX + StepNodeWH + NodeNameWidth + lineWidth, CenterY);
      }
     }
     //描述信息
     if (item.StepDesc != "")
     {
      Point pNode = new Point(initX + StepNodeWH, CenterY+10);
      e.Graphics.DrawString(item.StepDesc,new Font(nFont.FontFamily,10),brush, pNode);
     }
     index++;
     //8 is space width
     initX = initX + lineWidth + StepNodeWH+ NodeNameWidth+8;
    }
   }
  }

控件的使用:

List<StepEntity> list = new List<StepEntity>();
 list.Add(new StepEntity("1", "新開單", 1, "這里是該步驟的描述信息", eumStepState.Completed, null));
 list.Add(new StepEntity("2", "主管審批", 2, "這里是該步驟的描述信息", eumStepState.Waiting, null));
 list.Add(new StepEntity("3", "總經(jīng)理審批", 3, "這里是該步驟的描述信息", eumStepState.OutTime, null));
 list.Add(new StepEntity("2", "完成", 4, "這里是該步驟的描述信息", eumStepState.Waiting, null));
 this.stepViewer1.CurrentStep = 3;
 this.stepViewer1.ListDataSource = list;

同樣的,我們可以實(shí)現(xiàn)如下的timeline控件。

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • 詳解TreeView綁定數(shù)據(jù)庫(kù)

    詳解TreeView綁定數(shù)據(jù)庫(kù)

    這篇文章主要演示了TreeView如何與數(shù)據(jù)庫(kù)進(jìn)行綁定
    2015-07-07
  • C# 靈活使用類的方法

    C# 靈活使用類的方法

    本文主要介紹了C# 靈活使用類的方法,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • C#創(chuàng)建簡(jiǎn)單windows窗體應(yīng)用(加法器)

    C#創(chuàng)建簡(jiǎn)單windows窗體應(yīng)用(加法器)

    這篇文章主要為大家詳細(xì)介紹了C#創(chuàng)建一個(gè)簡(jiǎn)單windows窗體應(yīng)用的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • C# Invoke,begininvoke的用法詳解

    C# Invoke,begininvoke的用法詳解

    這篇文章主要介紹了C# Invoke,begininvoke的用法詳解,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2021-01-01
  • 詳解C#如何實(shí)現(xiàn)樹形圖列表

    詳解C#如何實(shí)現(xiàn)樹形圖列表

    這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)樹形圖列表,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以了解一下
    2022-12-12
  • WPF實(shí)現(xiàn)類似360安全衛(wèi)士界面的程序源碼分享

    WPF實(shí)現(xiàn)類似360安全衛(wèi)士界面的程序源碼分享

    最近在網(wǎng)上看到了新版的360安全衛(wèi)士,感覺界面還不錯(cuò),于是用WPF制作了一個(gè),時(shí)間有限,一些具體的控件沒(méi)有制作,用圖片代替了。感興趣的朋友一起跟著小編學(xué)習(xí)WPF實(shí)現(xiàn)類似360安全衛(wèi)士界面的程序源碼分享
    2015-09-09
  • c++指針使用形參改變實(shí)參的方法

    c++指針使用形參改變實(shí)參的方法

    下面小編就為大家?guī)?lái)一篇c++指針使用形參改變實(shí)參的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • C#實(shí)現(xiàn)對(duì)數(shù)組進(jìn)行隨機(jī)排序類實(shí)例

    C#實(shí)現(xiàn)對(duì)數(shù)組進(jìn)行隨機(jī)排序類實(shí)例

    這篇文章主要介紹了C#實(shí)現(xiàn)對(duì)數(shù)組進(jìn)行隨機(jī)排序類,實(shí)例分析了C#數(shù)組與隨機(jī)數(shù)操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-03-03
  • C#獲取計(jì)算機(jī)名,IP,MAC信息實(shí)現(xiàn)代碼

    C#獲取計(jì)算機(jī)名,IP,MAC信息實(shí)現(xiàn)代碼

    利用C#獲取計(jì)算機(jī)名,IP,MAC信息如何實(shí)現(xiàn),一直是網(wǎng)友們的頭疼問(wèn)題,本文整理了一些實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2012-11-11
  • LINQ基礎(chǔ)之From和GroupBy子句

    LINQ基礎(chǔ)之From和GroupBy子句

    這篇文章介紹了LINQ使用From和GroupBy子句的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04

最新評(píng)論