C#에서 단계 표시줄 컨트롤을 개발하기 위한 자세한 코드 설명(그림)

黄舟
풀어 주다: 2017-03-17 11:39:49
원래의
3249명이 탐색했습니다.

이 글에서는 참고할만한 좋은 C#을 이용하여 스텝 제어를 구현하는 단계를 주로 소개합니다. 아래 편집기를 사용하여 살펴보겠습니다.

지금은 많은 javascript 컨트롤이 있는데 매우 훌륭합니다. 그 중 하나는 아래 그림과 같이 단계입니다.

그럼 C#을 사용하여 단계 제어를 구현하는 방법은 무엇입니까?

먼저 StepEntity 클래스를 정의하여 스텝 바 노드 정보 :

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;
  }
 }
로그인 후 복사

StepViewer라는 사용자 컨트롤을 정의합니다.

public partial class StepViewer : UserControl
 {
  public StepViewer()
  {
   InitializeComponent();
   this.Height = 68;
  }
}
로그인 후 복사

다음과 같이 StepViewer 사용자 컨트롤에서 ListDataSource 속성을 정의합니다.

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

이 컨트롤의 페인트 메서드에서 다음 단계를 수행합니다. 막대 그리기:

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", "总经理审批", 3, "这里是该步骤的描述信息", eumStepState.OutTime, null));
 list.Add(new StepEntity("2", "完成", 4, "这里是该步骤的描述信息", eumStepState.Waiting, null));
 this.stepViewer1.CurrentStep = 3;
 this.stepViewer1.ListDataSource = list;
로그인 후 복사

마찬가지로 다음을 달성할 수 있습니다. 타임라인 제어.

위 내용은 C#에서 단계 표시줄 컨트롤을 개발하기 위한 자세한 코드 설명(그림)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
c#
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!