///  ///  publicpartialclassUCBtnsGroup:UserControl  {    ///    ///选中改变事件    ///    [Description("选中改变事件"),Category("自定义")]    publiceventEventHandlerSelectedItemChanged;    ///    ///Themdatasource    ///    privateDictionarym_dataSource=newDictionary();    ///    ///数据源    ///    ///Thedatasource.    [Description("数据源"),Category("自定义")]    publicDictionaryDataSource    {      get{returnm_dataSource;}      set      {        m_dataSource=value;        Reload();      }    }    ///    ///Themselectitem    ///    privateListm_selectItem=newList();    ///    ///选中项    ///    ///Theselectitem.    [Description("选中项"),Category("自定义")]    publicListSelectItem    {      get{returnm_selectItem;}      set      {        m_selectItem=value;        if(m_selectItem==null)          m_selectItem=newList();        SetSelected();      }    }    ///    ///Themismultiple    ///    privateboolm_isMultiple=false;    ///    ///是否多选    ///    ///trueifthisinstanceismultiple;otherwise,false.    [Description("是否多选"),Category("自定义")]    publicboolIsMultiple    {      get{returnm_isMultiple;}      set{m_isMultiple=value;}    }    ///    ///Initializesanewinstanceoftheclass.    ///    publicUCBtnsGroup()    {      InitializeComponent();    }    ///    ///Reloadsthisinstance.    ///    privatevoidReload()    {      try      {        ControlHelper.FreezeControl(flowLayoutPanel1,true);        this.flowLayoutPanel1.Controls.Clear();        if(DataSource!=null)        {          foreach(variteminDataSource)          {            UCBtnExtbtn=newUCBtnExt();            btn.BackColor=System.Drawing.Color.Transparent;            btn.BtnBackColor=System.Drawing.Color.White;            btn.BtnFont=newSystem.Drawing.Font("微软雅黑",10F);            btn.BtnForeColor=System.Drawing.Color.Gray;            btn.BtnText=item.Value;            btn.ConerRadius=5;            btn.Cursor=System.Windows.Forms.Cursors.Hand;            btn.FillColor=System.Drawing.Color.White;            btn.Font=newSystem.Drawing.Font("微软雅黑",15F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Pixel);            btn.IsRadius=true;            btn.IsShowRect=true;            btn.IsShowTips=false;            btn.Location=newSystem.Drawing.Point(5,5);            btn.Margin=newSystem.Windows.Forms.Padding(5);            btn.Name=item.Key;            btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);            btn.RectWidth=1;            btn.Size=newSystem.Drawing.Size(72,38);            btn.TabStop=false;            btn.BtnClick=btn_BtnClick;            this.flowLayoutPanel1.Controls.Add(btn);          }        }      }      finally      {        ControlHelper.FreezeControl(flowLayoutPanel1,false);      }      SetSelected();    }    ///    ///HandlestheBtnClickeventofthebtncontrol.    ///    ///Thesourceoftheevent.    ///Theinstancecontainingtheeventdata.    voidbtn_BtnClick(objectsender,EventArgse)    {      varbtn=senderasUCBtnExt;      if(m_selectItem.Contains(btn.Name))      {        btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);        m_selectItem.Remove(btn.Name);      }      else      {        if(!m_isMultiple)        {          foreach(variteminm_selectItem)          {            varlst=this.flowLayoutPanel1.Controls.Find(item,false);            if(lst.Length==1)            {              var_btn=lst[0]asUCBtnExt;              _btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);            }          }          m_selectItem.Clear();        }        btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);        m_selectItem.Add(btn.Name);      }      if(SelectedItemChanged!=null)        SelectedItemChanged(this,e);    }    ///    ///Setstheselected.    ///    privatevoidSetSelected()    {      if(m_selectItem!=null&&m_selectItem.Count>0&&DataSource!=null&&DataSource.Count>0)      {        try        {          ControlHelper.FreezeControl(flowLayoutPanel1,true);          if(m_isMultiple)          {            foreach(variteminm_selectItem)            {              varlst=this.flowLayoutPanel1.Controls.Find(item,false);              if(lst.Length==1)              {                varbtn=lst[0]asUCBtnExt;                btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);              }            }          }          else          {            UCBtnExtbtn=null;            foreach(variteminm_selectItem)            {              varlst=this.flowLayoutPanel1.Controls.Find(item,false);              if(lst.Length==1)              {                btn=lst[0]asUCBtnExt;                break;              }            }            if(btn!=null)            {              m_selectItem=newList(){btn.Name};              btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);            }          }        }        finally        {          ControlHelper.FreezeControl(flowLayoutPanel1,false);        }      }    }  }}usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Drawing.Drawing2D;namespaceHZH_Controls.Controls{  ///  ///ClassUCStep.  ///Implementsthe  ///  ///  [DefaultEvent("IndexChecked")]  publicpartialclassUCStep:UserControl  {    ///    ///Occurswhen[indexchecked].    ///    [Description("步骤更改事件"),Category("自定义")]    publiceventEventHandlerIndexChecked;    ///    ///Themstepbackcolor    ///    privateColorm_stepBackColor=Color.FromArgb(189,189,189);    ///    ///步骤背景色    ///    ///Thecolorofthestepback.    [Description("步骤背景色"),Category("自定义")]    publicColorStepBackColor    {      get{returnm_stepBackColor;}      set      {        m_stepBackColor=value;        Refresh();      }    }    ///    ///Themstepforecolor    ///    privateColorm_stepForeColor=Color.FromArgb(255,77,59);    ///    ///步骤前景色    ///    ///Thecolorofthestepfore.    [Description("步骤前景色"),Category("自定义")]    publicColorStepForeColor    {      get{returnm_stepForeColor;}      set      {        m_stepForeColor=value;        Refresh();      }    }    ///    ///Themstepfontcolor    ///    privateColorm_stepFontColor=Color.White;    ///    ///步骤文字颜色    ///    ///Thecolorofthestepfont.    [Description("步骤文字景色"),Category("自定义")]    publicColorStepFontColor    {      get{returnm_stepFontColor;}      set      {        m_stepFontColor=value;        Refresh();      }    }    ///    ///Themstepwidth    ///    privateintm_stepWidth=35;    ///    ///步骤宽度    ///    ///Thewidthofthestep.    [Description("步骤宽度景色"),Category("自定义")]    publicintStepWidth    {      get{returnm_stepWidth;}      set      {        m_stepWidth=value;        Refresh();      }    }    ///    ///Themsteps    ///    privatestring[]m_steps=newstring[]{"step1","step2","step3"};    ///    ///Getsorsetsthesteps.    ///    ///Thesteps.    [Description("步骤"),Category("自定义")]    publicstring[]Steps    {      get{returnm_steps;}      set      {        if(m_steps==null||m_steps.Length<=1)          return;        m_steps=value;        Refresh();      }    }    ///    ///Themstepindex    ///    privateintm_stepIndex=0;    ///    ///Getsorsetstheindexofthestep.    ///    ///Theindexofthestep.    [Description("步骤位置"),Category("自定义")]    publicintStepIndex    {      get{returnm_stepIndex;}      set      {        if(value>Steps.Length)          return;        m_stepIndex=value;        Refresh();        if(IndexChecked!=null)        {          IndexChecked(this,null);        }      }    }    ///    ///Themlinewidth    ///    privateintm_lineWidth=2;    ///    ///Getsorsetsthewidthoftheline.    ///    ///Thewidthoftheline.    [Description("连接线宽度,最小2"),Category("自定义")]    publicintLineWidth    {      get{returnm_lineWidth;}      set      {        if(value<2)          return;        m_lineWidth=value;        Refresh();      }    }    ///    ///Themimgcompleted    ///    privateImagem_imgCompleted=null;    ///    ///Getsorsetstheimgcompleted.    ///    ///Theimgcompleted.    [Description("已完成步骤图片,当不为空时,已完成步骤将不再显示数字,建议24*24大小"),Category("自定义")]    publicImageImgCompleted    {      get{returnm_imgCompleted;}      set      {        m_imgCompleted=value;        Refresh();      }    }    ///    ///ThemLSTcacherect    ///    Listm_lstCacheRect=newList();    ///    ///Initializesanewinstanceoftheclass.    ///    publicUCStep()    {      InitializeComponent();      this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);      this.SetStyle(ControlStyles.DoubleBuffer,true);      this.SetStyle(ControlStyles.ResizeRedraw,true);      this.SetStyle(ControlStyles.Selectable,true);      this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);      this.SetStyle(ControlStyles.UserPaint,true);      this.MouseDown=UCStep_MouseDown;    }    ///    ///HandlestheMouseDowneventoftheUCStepcontrol.    ///    ///Thesourceoftheevent.    ///Theinstancecontainingtheeventdata.    voidUCStep_MouseDown(objectsender,MouseEventArgse)    {      varindex=m_lstCacheRect.FindIndex(p=>p.Contains(e.Location));      if(index>=0)      {        StepIndex=index1;      }    }    ///    ///引发事件。    ///    ///包含事件数据的。    protectedoverridevoidOnPaint(PaintEventArgse)    {      base.OnPaint(e);      varg=e.Graphics;      g.SetGDIHigh();      if(m_steps!=null&&m_steps.Length>0)      {        System.Drawing.SizeFsizeFirst=g.MeasureString(m_steps[0],this.Font);        inty=(this.Height-m_stepWidth-10-(int)sizeFirst.Height)/2;        if(y<0)          y=0;        intintTxtY=ym_stepWidth10;        intintLeft=0;        if(sizeFirst.Width>m_stepWidth)        {          intLeft=(int)(sizeFirst.Width-m_stepWidth)/21;        }        intintRight=0;        System.Drawing.SizeFsizeEnd=g.MeasureString(m_steps[m_steps.Length-1],this.Font);        if(sizeEnd.Width>m_stepWidth)        {          intRight=(int)(sizeEnd.Width-m_stepWidth)/21;        }        intintSplitWidth=20;        intSplitWidth=(this.Width-m_steps.Length-(m_steps.Length*m_stepWidth)-intRight-intLeft)/(m_steps.Length-1);        if(intSplitWidth<20)          intSplitWidth=20;        m_lstCacheRect=newList();        for(inti=0;ii)          {            g.FillEllipse(newSolidBrush(m_stepForeColor),newRectangle(newPoint(intLefti*(m_stepWidthintSplitWidth)2,y2),newSize(m_stepWidth-4,m_stepWidth-4)));          }          if(m_stepIndex>i&&m_imgCompleted!=null)          {            g.DrawImage(m_imgCompleted,newRectangle(newPoint((intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-24)/2),y(m_stepWidth-24)/2),newSize(24,24)),0,0,m_imgCompleted.Width,m_imgCompleted.Height,GraphicsUnit.Pixel,null);          }          else          {            System.Drawing.SizeF_numSize=g.MeasureString((i1).ToString(),this.Font);            g.DrawString((i1).ToString(),Font,newSolidBrush(m_stepFontColor),newPoint(intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-(int)_numSize.Width)/21,y(m_stepWidth-(int)_numSize.Height)/21));          }          #endregion          System.Drawing.SizeFsizeTxt=g.MeasureString(m_steps[i],this.Font);          g.DrawString(m_steps[i],Font,newSolidBrush(m_stepIndex>i?m_stepForeColor:m_stepBackColor),newPoint(intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-(int)sizeTxt.Width)/21,intTxtY));        }        for(inti=0;ii)          {            if(i!=m_steps.Length-1)            {              if(m_stepIndex==i1)              {                g.DrawLine(newPen(m_stepForeColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidthintSplitWidth/2,y((m_stepWidth)/2)));                g.DrawLine(newPen(m_stepBackColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidthintSplitWidth/2,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));              }              else              {                g.DrawLine(newPen(m_stepForeColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));              }            }          }          else          {            if(i!=m_steps.Length-1)            {              g.DrawLine(newPen(m_stepBackColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));            }          }        }      }    }  }}-IMDN开发者社群-imdn.cn">   ///  ///  publicpartialclassUCBtnsGroup:UserControl  {    ///    ///选中改变事件    ///    [Description("选中改变事件"),Category("自定义")]    publiceventEventHandlerSelectedItemChanged;    ///    ///Themdatasource    ///    privateDictionarym_dataSource=newDictionary();    ///    ///数据源    ///    ///Thedatasource.    [Description("数据源"),Category("自定义")]    publicDictionaryDataSource    {      get{returnm_dataSource;}      set      {        m_dataSource=value;        Reload();      }    }    ///    ///Themselectitem    ///    privateListm_selectItem=newList();    ///    ///选中项    ///    ///Theselectitem.    [Description("选中项"),Category("自定义")]    publicListSelectItem    {      get{returnm_selectItem;}      set      {        m_selectItem=value;        if(m_selectItem==null)          m_selectItem=newList();        SetSelected();      }    }    ///    ///Themismultiple    ///    privateboolm_isMultiple=false;    ///    ///是否多选    ///    ///trueifthisinstanceismultiple;otherwise,false.    [Description("是否多选"),Category("自定义")]    publicboolIsMultiple    {      get{returnm_isMultiple;}      set{m_isMultiple=value;}    }    ///    ///Initializesanewinstanceoftheclass.    ///    publicUCBtnsGroup()    {      InitializeComponent();    }    ///    ///Reloadsthisinstance.    ///    privatevoidReload()    {      try      {        ControlHelper.FreezeControl(flowLayoutPanel1,true);        this.flowLayoutPanel1.Controls.Clear();        if(DataSource!=null)        {          foreach(variteminDataSource)          {            UCBtnExtbtn=newUCBtnExt();            btn.BackColor=System.Drawing.Color.Transparent;            btn.BtnBackColor=System.Drawing.Color.White;            btn.BtnFont=newSystem.Drawing.Font("微软雅黑",10F);            btn.BtnForeColor=System.Drawing.Color.Gray;            btn.BtnText=item.Value;            btn.ConerRadius=5;            btn.Cursor=System.Windows.Forms.Cursors.Hand;            btn.FillColor=System.Drawing.Color.White;            btn.Font=newSystem.Drawing.Font("微软雅黑",15F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Pixel);            btn.IsRadius=true;            btn.IsShowRect=true;            btn.IsShowTips=false;            btn.Location=newSystem.Drawing.Point(5,5);            btn.Margin=newSystem.Windows.Forms.Padding(5);            btn.Name=item.Key;            btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);            btn.RectWidth=1;            btn.Size=newSystem.Drawing.Size(72,38);            btn.TabStop=false;            btn.BtnClick=btn_BtnClick;            this.flowLayoutPanel1.Controls.Add(btn);          }        }      }      finally      {        ControlHelper.FreezeControl(flowLayoutPanel1,false);      }      SetSelected();    }    ///    ///HandlestheBtnClickeventofthebtncontrol.    ///    ///Thesourceoftheevent.    ///Theinstancecontainingtheeventdata.    voidbtn_BtnClick(objectsender,EventArgse)    {      varbtn=senderasUCBtnExt;      if(m_selectItem.Contains(btn.Name))      {        btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);        m_selectItem.Remove(btn.Name);      }      else      {        if(!m_isMultiple)        {          foreach(variteminm_selectItem)          {            varlst=this.flowLayoutPanel1.Controls.Find(item,false);            if(lst.Length==1)            {              var_btn=lst[0]asUCBtnExt;              _btn.RectColor=System.Drawing.Color.FromArgb(224,224,224);            }          }          m_selectItem.Clear();        }        btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);        m_selectItem.Add(btn.Name);      }      if(SelectedItemChanged!=null)        SelectedItemChanged(this,e);    }    ///    ///Setstheselected.    ///    privatevoidSetSelected()    {      if(m_selectItem!=null&&m_selectItem.Count>0&&DataSource!=null&&DataSource.Count>0)      {        try        {          ControlHelper.FreezeControl(flowLayoutPanel1,true);          if(m_isMultiple)          {            foreach(variteminm_selectItem)            {              varlst=this.flowLayoutPanel1.Controls.Find(item,false);              if(lst.Length==1)              {                varbtn=lst[0]asUCBtnExt;                btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);              }            }          }          else          {            UCBtnExtbtn=null;            foreach(variteminm_selectItem)            {              varlst=this.flowLayoutPanel1.Controls.Find(item,false);              if(lst.Length==1)              {                btn=lst[0]asUCBtnExt;                break;              }            }            if(btn!=null)            {              m_selectItem=newList(){btn.Name};              btn.RectColor=System.Drawing.Color.FromArgb(255,77,59);            }          }        }        finally        {          ControlHelper.FreezeControl(flowLayoutPanel1,false);        }      }    }  }}usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Drawing.Drawing2D;namespaceHZH_Controls.Controls{  ///  ///ClassUCStep.  ///Implementsthe  ///  ///  [DefaultEvent("IndexChecked")]  publicpartialclassUCStep:UserControl  {    ///    ///Occurswhen[indexchecked].    ///    [Description("步骤更改事件"),Category("自定义")]    publiceventEventHandlerIndexChecked;    ///    ///Themstepbackcolor    ///    privateColorm_stepBackColor=Color.FromArgb(189,189,189);    ///    ///步骤背景色    ///    ///Thecolorofthestepback.    [Description("步骤背景色"),Category("自定义")]    publicColorStepBackColor    {      get{returnm_stepBackColor;}      set      {        m_stepBackColor=value;        Refresh();      }    }    ///    ///Themstepforecolor    ///    privateColorm_stepForeColor=Color.FromArgb(255,77,59);    ///    ///步骤前景色    ///    ///Thecolorofthestepfore.    [Description("步骤前景色"),Category("自定义")]    publicColorStepForeColor    {      get{returnm_stepForeColor;}      set      {        m_stepForeColor=value;        Refresh();      }    }    ///    ///Themstepfontcolor    ///    privateColorm_stepFontColor=Color.White;    ///    ///步骤文字颜色    ///    ///Thecolorofthestepfont.    [Description("步骤文字景色"),Category("自定义")]    publicColorStepFontColor    {      get{returnm_stepFontColor;}      set      {        m_stepFontColor=value;        Refresh();      }    }    ///    ///Themstepwidth    ///    privateintm_stepWidth=35;    ///    ///步骤宽度    ///    ///Thewidthofthestep.    [Description("步骤宽度景色"),Category("自定义")]    publicintStepWidth    {      get{returnm_stepWidth;}      set      {        m_stepWidth=value;        Refresh();      }    }    ///    ///Themsteps    ///    privatestring[]m_steps=newstring[]{"step1","step2","step3"};    ///    ///Getsorsetsthesteps.    ///    ///Thesteps.    [Description("步骤"),Category("自定义")]    publicstring[]Steps    {      get{returnm_steps;}      set      {        if(m_steps==null||m_steps.Length<=1)          return;        m_steps=value;        Refresh();      }    }    ///    ///Themstepindex    ///    privateintm_stepIndex=0;    ///    ///Getsorsetstheindexofthestep.    ///    ///Theindexofthestep.    [Description("步骤位置"),Category("自定义")]    publicintStepIndex    {      get{returnm_stepIndex;}      set      {        if(value>Steps.Length)          return;        m_stepIndex=value;        Refresh();        if(IndexChecked!=null)        {          IndexChecked(this,null);        }      }    }    ///    ///Themlinewidth    ///    privateintm_lineWidth=2;    ///    ///Getsorsetsthewidthoftheline.    ///    ///Thewidthoftheline.    [Description("连接线宽度,最小2"),Category("自定义")]    publicintLineWidth    {      get{returnm_lineWidth;}      set      {        if(value<2)          return;        m_lineWidth=value;        Refresh();      }    }    ///    ///Themimgcompleted    ///    privateImagem_imgCompleted=null;    ///    ///Getsorsetstheimgcompleted.    ///    ///Theimgcompleted.    [Description("已完成步骤图片,当不为空时,已完成步骤将不再显示数字,建议24*24大小"),Category("自定义")]    publicImageImgCompleted    {      get{returnm_imgCompleted;}      set      {        m_imgCompleted=value;        Refresh();      }    }    ///    ///ThemLSTcacherect    ///    Listm_lstCacheRect=newList();    ///    ///Initializesanewinstanceoftheclass.    ///    publicUCStep()    {      InitializeComponent();      this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);      this.SetStyle(ControlStyles.DoubleBuffer,true);      this.SetStyle(ControlStyles.ResizeRedraw,true);      this.SetStyle(ControlStyles.Selectable,true);      this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);      this.SetStyle(ControlStyles.UserPaint,true);      this.MouseDown=UCStep_MouseDown;    }    ///    ///HandlestheMouseDowneventoftheUCStepcontrol.    ///    ///Thesourceoftheevent.    ///Theinstancecontainingtheeventdata.    voidUCStep_MouseDown(objectsender,MouseEventArgse)    {      varindex=m_lstCacheRect.FindIndex(p=>p.Contains(e.Location));      if(index>=0)      {        StepIndex=index1;      }    }    ///    ///引发事件。    ///    ///包含事件数据的。    protectedoverridevoidOnPaint(PaintEventArgse)    {      base.OnPaint(e);      varg=e.Graphics;      g.SetGDIHigh();      if(m_steps!=null&&m_steps.Length>0)      {        System.Drawing.SizeFsizeFirst=g.MeasureString(m_steps[0],this.Font);        inty=(this.Height-m_stepWidth-10-(int)sizeFirst.Height)/2;        if(y<0)          y=0;        intintTxtY=ym_stepWidth10;        intintLeft=0;        if(sizeFirst.Width>m_stepWidth)        {          intLeft=(int)(sizeFirst.Width-m_stepWidth)/21;        }        intintRight=0;        System.Drawing.SizeFsizeEnd=g.MeasureString(m_steps[m_steps.Length-1],this.Font);        if(sizeEnd.Width>m_stepWidth)        {          intRight=(int)(sizeEnd.Width-m_stepWidth)/21;        }        intintSplitWidth=20;        intSplitWidth=(this.Width-m_steps.Length-(m_steps.Length*m_stepWidth)-intRight-intLeft)/(m_steps.Length-1);        if(intSplitWidth<20)          intSplitWidth=20;        m_lstCacheRect=newList();        for(inti=0;ii)          {            g.FillEllipse(newSolidBrush(m_stepForeColor),newRectangle(newPoint(intLefti*(m_stepWidthintSplitWidth)2,y2),newSize(m_stepWidth-4,m_stepWidth-4)));          }          if(m_stepIndex>i&&m_imgCompleted!=null)          {            g.DrawImage(m_imgCompleted,newRectangle(newPoint((intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-24)/2),y(m_stepWidth-24)/2),newSize(24,24)),0,0,m_imgCompleted.Width,m_imgCompleted.Height,GraphicsUnit.Pixel,null);          }          else          {            System.Drawing.SizeF_numSize=g.MeasureString((i1).ToString(),this.Font);            g.DrawString((i1).ToString(),Font,newSolidBrush(m_stepFontColor),newPoint(intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-(int)_numSize.Width)/21,y(m_stepWidth-(int)_numSize.Height)/21));          }          #endregion          System.Drawing.SizeFsizeTxt=g.MeasureString(m_steps[i],this.Font);          g.DrawString(m_steps[i],Font,newSolidBrush(m_stepIndex>i?m_stepForeColor:m_stepBackColor),newPoint(intLefti*(m_stepWidthintSplitWidth)(m_stepWidth-(int)sizeTxt.Width)/21,intTxtY));        }        for(inti=0;ii)          {            if(i!=m_steps.Length-1)            {              if(m_stepIndex==i1)              {                g.DrawLine(newPen(m_stepForeColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidthintSplitWidth/2,y((m_stepWidth)/2)));                g.DrawLine(newPen(m_stepBackColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidthintSplitWidth/2,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));              }              else              {                g.DrawLine(newPen(m_stepForeColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));              }            }          }          else          {            if(i!=m_steps.Length-1)            {              g.DrawLine(newPen(m_stepBackColor,m_lineWidth),newPoint(intLefti*(m_stepWidthintSplitWidth)m_stepWidth-3,y((m_stepWidth)/2)),newPoint(intLeft(i1)*(m_stepWidthintSplitWidth)10,y((m_stepWidth)/2)));            }          }        }      }    }  }} - IMDN开发者社群-imdn.cn">
登录
首页 » C# » c#Winform自定义控件

c#Winform自定义控件

于 2020-12-11 发布
0 298
下载积分: 1 下载次数: 3

代码说明:

c#Winform自定义控件-基类控件,按钮,有图标的按钮,选择按钮组,复选框,单选框,进度条,分割线,树,横向列表,列表,分页控件,导航菜单,键盘,文本框,表格,日期控件,Tab页,下拉框,步骤控件,有标题的面板,圆形进度条,面包屑导航,开关等等。using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;namespace HZH_Controls.Controls{    ///     /// Class UCBtnsGroup.    /// Implements the     ///     ///     public partial class UCBtnsGroup : UserControl    {        ///         /// 选中改变事件        ///         [Description("选中改变事件"), Category("自定义")]        public event EventHandler SelectedItemChanged;        ///         /// The m data source        ///         private Dictionary m_dataSource = new Dictionary();        ///         /// 数据源        ///         /// The data source.        [Description("数据源"), Category("自定义")]        public Dictionary DataSource        {            get { return m_dataSource; }            set            {                m_dataSource = value;                Reload();            }        }        ///         /// The m select item        ///         private List m_selectItem = new List();        ///         /// 选中项        ///         /// The select item.        [Description("选中项"), Category("自定义")]        public List SelectItem        {            get { return m_selectItem; }            set            {                m_selectItem = value;                if (m_selectItem == null)                    m_selectItem = new List();                SetSelected();            }        }        ///         /// The m is multiple        ///         private bool m_isMultiple = false;        ///         /// 是否多选        ///         /// true if this instance is multiple; otherwise, false.        [Description("是否多选"), Category("自定义")]        public bool IsMultiple        {            get { return m_isMultiple; }            set { m_isMultiple = value; }        }        ///         /// Initializes a new instance of the class.        ///         public UCBtnsGroup()        {            InitializeComponent();        }        ///         /// Reloads this instance.        ///         private void Reload()        {            try            {                ControlHelper.FreezeControl(flowLayoutPanel1, true);                this.flowLayoutPanel1.Controls.Clear();                if (DataSource != null)                {                    foreach (var item in DataSource)                    {                        UCBtnExt btn = new UCBtnExt();                        btn.BackColor = System.Drawing.Color.Transparent;                        btn.BtnBackColor = System.Drawing.Color.White;                        btn.BtnFont = new System.Drawing.Font("微软雅黑", 10F);                        btn.BtnForeColor = System.Drawing.Color.Gray;                        btn.BtnText = item.Value;                        btn.ConerRadius = 5;                        btn.Cursor = System.Windows.Forms.Cursors.Hand;                        btn.FillColor = System.Drawing.Color.White;                        btn.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);                        btn.IsRadius = true;                        btn.IsShowRect = true;                        btn.IsShowTips = false;                        btn.Location = new System.Drawing.Point(5, 5);                        btn.Margin = new System.Windows.Forms.Padding(5);                        btn.Name = item.Key;                        btn.RectColor = System.Drawing.Color.FromArgb(224, 224, 224);                        btn.RectWidth = 1;                        btn.Size = new System.Drawing.Size(72, 38);                        btn.TabStop = false;                        btn.BtnClick = btn_BtnClick;                        this.flowLayoutPanel1.Controls.Add(btn);                    }                }            }            finally            {                ControlHelper.FreezeControl(flowLayoutPanel1, false);            }            SetSelected();        }        ///         /// Handles the BtnClick event of the btn control.        ///         /// The source of the event.        /// The instance containing the event data.        void btn_BtnClick(object sender, EventArgs e)        {            var btn = sender as UCBtnExt;            if (m_selectItem.Contains(btn.Name))            {                btn.RectColor = System.Drawing.Color.FromArgb(224, 224, 224);                m_selectItem.Remove(btn.Name);            }            else            {                if (!m_isMultiple)                {                    foreach (var item in m_selectItem)                    {                        var lst = this.flowLayoutPanel1.Controls.Find(item, false);                        if (lst.Length == 1)                        {                            var _btn = lst[0] as UCBtnExt;                            _btn.RectColor = System.Drawing.Color.FromArgb(224, 224, 224);                        }                    }                    m_selectItem.Clear();                }                btn.RectColor = System.Drawing.Color.FromArgb(255, 77, 59);                m_selectItem.Add(btn.Name);            }            if (SelectedItemChanged != null)                SelectedItemChanged(this, e);        }        ///         /// Sets the selected.        ///         private void SetSelected()        {            if (m_selectItem != null && m_selectItem.Count > 0 && DataSource != null && DataSource.Count > 0)            {                try                {                    ControlHelper.FreezeControl(flowLayoutPanel1, true);                    if (m_isMultiple)                    {                        foreach (var item in m_selectItem)                        {                            var lst = this.flowLayoutPanel1.Controls.Find(item, false);                            if (lst.Length == 1)                            {                                var btn = lst[0] as UCBtnExt;                                btn.RectColor = System.Drawing.Color.FromArgb(255, 77, 59);                            }                        }                    }                    else                    {                        UCBtnExt btn = null;                        foreach (var item in m_selectItem)                        {                            var lst = this.flowLayoutPanel1.Controls.Find(item, false);                            if (lst.Length == 1)                            {                                btn = lst[0] as UCBtnExt;                                break;                            }                        }                        if (btn != null)                        {                            m_selectItem = new List() { btn.Name };                            btn.RectColor = System.Drawing.Color.FromArgb(255, 77, 59);                        }                    }                }                finally                {                    ControlHelper.FreezeControl(flowLayoutPanel1, false);                }            }        }    }}using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;namespace HZH_Controls.Controls{    ///     /// Class UCStep.    /// Implements the     ///     ///     [DefaultEvent("IndexChecked")]    public partial class UCStep : UserControl    {        ///         /// Occurs when [index checked].        ///         [Description("步骤更改事件"), Category("自定义")]        public event EventHandler IndexChecked;        ///         /// The m step back color        ///         private Color m_stepBackColor = Color.FromArgb(189, 189, 189);        ///         /// 步骤背景色        ///         /// The color of the step back.        [Description("步骤背景色"), Category("自定义")]        public Color StepBackColor        {            get { return m_stepBackColor; }            set            {                m_stepBackColor = value;                Refresh();            }        }        ///         /// The m step fore color        ///         private Color m_stepForeColor = Color.FromArgb(255, 77, 59);        ///         /// 步骤前景色        ///         /// The color of the step fore.        [Description("步骤前景色"), Category("自定义")]        public Color StepForeColor        {            get { return m_stepForeColor; }            set            {                m_stepForeColor = value;                Refresh();            }        }        ///         /// The m step font color        ///         private Color m_stepFontColor = Color.White;        ///         /// 步骤文字颜色        ///         /// The color of the step font.        [Description("步骤文字景色"), Category("自定义")]        public Color StepFontColor        {            get { return m_stepFontColor; }            set            {                m_stepFontColor = value;                Refresh();            }        }        ///         /// The m step width        ///         private int m_stepWidth = 35;        ///         /// 步骤宽度        ///         /// The width of the step.        [Description("步骤宽度景色"), Category("自定义")]        public int StepWidth        {            get { return m_stepWidth; }            set            {                m_stepWidth = value;                Refresh();            }        }        ///         /// The m steps        ///         private string[] m_steps = new string[] { "step1", "step2", "step3" };        ///         /// Gets or sets the steps.        ///         /// The steps.        [Description("步骤"), Category("自定义")]        public string[] Steps        {            get { return m_steps; }            set            {                if (m_steps == null || m_steps.Length Steps.Length)                    return;                m_stepIndex = value;                Refresh();                if (IndexChecked != null)                {                    IndexChecked(this, null);                }            }        }        ///         /// The m line width        ///         private int m_lineWidth = 2;        ///         /// Gets or sets the width of the line.        ///         /// The width of the line.        [Description("连接线宽度,最小2"), Category("自定义")]        public int LineWidth        {            get { return m_lineWidth; }            set            {                if (value < 2)                    return;                m_lineWidth = value;                Refresh();            }        }        ///         /// The m img completed        ///         private Image m_imgCompleted = null;        ///         /// Gets or sets the img completed.        ///         /// The img completed.        [Description("已完成步骤图片,当不为空时,已完成步骤将不再显示数字,建议24*24大小"), Category("自定义")]        public Image ImgCompleted        {            get { return m_imgCompleted; }            set            {                m_imgCompleted = value;                Refresh();            }        }        ///         /// The m LST cache rect        ///         List m_lstCacheRect = new List();        ///         /// Initializes a new instance of the class.        ///         public UCStep()        {            InitializeComponent();            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);            this.SetStyle(ControlStyles.DoubleBuffer, true);            this.SetStyle(ControlStyles.ResizeRedraw, true);            this.SetStyle(ControlStyles.Selectable, true);            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);            this.SetStyle(ControlStyles.UserPaint, true);            this.MouseDown = UCStep_MouseDown;        }        ///         /// Handles the MouseDown event of the UCStep control.        ///         /// The source of the event.        /// The instance containing the event data.        void UCStep_MouseDown(object sender, MouseEventArgs e)        {            var index = m_lstCacheRect.FindIndex(p => p.Contains(e.Location));            if (index >= 0)            {                StepIndex = index 1;            }        }        ///         /// 引发 事件。        ///         /// 包含事件数据的 。        protected override void OnPaint(PaintEventArgs e)        {            base.OnPaint(e);            var g = e.Graphics;            g.SetGDIHigh();            if (m_steps != null && m_steps.Length > 0)            {                System.Drawing.SizeF sizeFirst = g.MeasureString(m_steps[0], this.Font);                int y = (this.Height - m_stepWidth - 10 - (int)sizeFirst.Height) / 2;                if (y < 0)                    y = 0;                int intTxtY = y m_stepWidth 10;                int intLeft = 0;                if (sizeFirst.Width > m_stepWidth)                {                    intLeft = (int)(sizeFirst.Width - m_stepWidth) / 2 1;                }                int intRight = 0;                System.Drawing.SizeF sizeEnd = g.MeasureString(m_steps[m_steps.Length - 1], this.Font);                if (sizeEnd.Width > m_stepWidth)                {                    intRight = (int)(sizeEnd.Width - m_stepWidth) / 2 1;                }                int intSplitWidth = 20;                intSplitWidth = (this.Width - m_steps.Length - (m_steps.Length * m_stepWidth) - intRight - intLeft) / (m_steps.Length - 1);                if (intSplitWidth < 20)                    intSplitWidth = 20;                m_lstCacheRect = new List();                for (int i = 0; i < m_steps.Length; i )                {                    #region 画圆,横线                    Rectangle rectEllipse = new Rectangle(new Point(intLeft i * (m_stepWidth intSplitWidth), y), new Size(m_stepWidth, m_stepWidth));                    m_lstCacheRect.Add(rectEllipse);                    g.FillEllipse(new SolidBrush(m_stepBackColor), rectEllipse);                    if (m_stepIndex > i)                    {                        g.FillEllipse(new SolidBrush(m_stepForeColor), new Rectangle(new Point(intLeft i * (m_stepWidth intSplitWidth) 2, y 2), new Size(m_stepWidth - 4, m_stepWidth - 4)));                    }                    if (m_stepIndex > i && m_imgCompleted != null)                    {                        g.DrawImage(m_imgCompleted, new Rectangle(new Point((intLeft i * (m_stepWidth intSplitWidth) (m_stepWidth - 24) / 2), y (m_stepWidth - 24) / 2), new Size(24, 24)), 0, 0, m_imgCompleted.Width, m_imgCompleted.Height, GraphicsUnit.Pixel, null);                    }                    else                    {                        System.Drawing.SizeF _numSize = g.MeasureString((i 1).ToString(), this.Font);                        g.DrawString((i 1).ToString(), Font, new SolidBrush(m_stepFontColor), new Point(intLeft i * (m_stepWidth intSplitWidth) (m_stepWidth - (int)_numSize.Width) / 2 1, y (m_stepWidth - (int)_numSize.Height) / 2 1));                    }                    #endregion                    System.Drawing.SizeF sizeTxt = g.MeasureString(m_steps[i], this.Font);                    g.DrawString(m_steps[i], Font, new SolidBrush(m_stepIndex > i ? m_stepForeColor : m_stepBackColor), new Point(intLeft i * (m_stepWidth intSplitWidth) (m_stepWidth - (int)sizeTxt.Width) / 2 1, intTxtY));                }                for (int i = 0; i < m_steps.Length; i )                {                    if (m_stepIndex > i)                    {                        if (i != m_steps.Length - 1)                        {                            if (m_stepIndex == i 1)                            {                                g.DrawLine(new Pen(m_stepForeColor, m_lineWidth), new Point(intLeft i * (m_stepWidth intSplitWidth) m_stepWidth - 3, y ((m_stepWidth) / 2)), new Point(intLeft i * (m_stepWidth intSplitWidth) m_stepWidth intSplitWidth / 2, y ((m_stepWidth) / 2)));                                g.DrawLine(new Pen(m_stepBackColor, m_lineWidth), new Point(intLeft i * (m_stepWidth intSplitWidth) m_stepWidth intSplitWidth / 2, y ((m_stepWidth) / 2)), new Point(intLeft (i 1) * (m_stepWidth intSplitWidth) 10, y ((m_stepWidth) / 2)));                            }                            else                            {                                g.DrawLine(new Pen(m_stepForeColor, m_lineWidth), new Point(intLeft i * (m_stepWidth intSplitWidth) m_stepWidth - 3, y ((m_stepWidth) / 2)), new Point(intLeft (i 1) * (m_stepWidth intSplitWidth) 10, y ((m_stepWidth) / 2)));                            }                        }                    }                    else                    {                        if (i != m_steps.Length - 1)                        {                            g.DrawLine(new Pen(m_stepBackColor, m_lineWidth), new Point(intLeft i * (m_stepWidth intSplitWidth) m_stepWidth - 3, y ((m_stepWidth) / 2)), new Point(intLeft (i 1) * (m_stepWidth intSplitWidth) 10, y ((m_stepWidth) / 2)));                        }                    }                }            }        }    }}

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# 最小化截图示例源码下载
    C# 最小化截图示例源码下载
    2014-04-02下载
    积分:1
  • PAT | 蓝桥 | LeetCode学习路径 & 刷题经验.pdf(共35页)
    PAT | 蓝桥 | LeetCode学习路径 & 刷题经验.pdf(共35页)
    2020-04-12下载
    积分:1
  • C# 将图片保存到数据库并取出源码下载
    C# 将图片保存到数据库并取出源码下载
    2015-04-23下载
    积分:1
  • 利用c#写的jpg拼图软件,可以随意剪切和拼接(钩子源码)
    利用c#写的jpg拼图软件,可以随意剪切和拼接using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;using System.Runtime.InteropServices;namespace AutoDrawRect{ public class MouseHook { //好吧这个没有用到 private bool isSet; public bool IsSet { get { return isSet; } } //这个也没有用到 private int handleOfHook; public int HandleOfHook { get { return handleOfHook; } } //这个还是没有用到、、、淡定! private bool isStopMsg; public bool IsStopMsg { get { return isStopMsg; } set { isStopMsg = value; } } //自己定义了一个事件 放到Hook里面去 public delegate void MEventhandler(object sender, MouseInfoEventArys e); public event MEventhandler HooKMouseEvent; [DllImport("user32.dll")]//设置钩子 第二个参数为回调函数指针 public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hmod, int dwThreadid); [DllImport("user32.dll")]//传递到下一个钩子 public static extern int CallNextHookEx(int hHook, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")]//卸载钩子 public static extern bool UnhookWindowsHookEx(int hHook); [DllImport("kernel32.dll")]//获取模块句柄 public static extern IntPtr GetModuleHandle(string lpModuleName); public const int WH_MOUSE_LL = 14;//全局鼠标Hook 7是局部的 13全局键盘 2局部键盘 public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);//话说c#里面委托就是函数指针?、 private const int WM_LBUTTONDOWN = 0x201; //在Hook里面判断是否左键点下 private const int WM_RBUTTONUP = 0x205; //在Hook里面判断是否右键抬起 public struct POINT {//鼠标位置的结构体 public int x; public int y; } public struct MouseLLInfo {//全局鼠标Hook的结构体 public POINT pt; //其实这里可以用Point只是这个新建的类里面没有应用System.Windows.Forms(应该是这个) public int mouseData; public int flags; public int time; public int dwExtraInfo; } GCHandle gc;//好吧 话说就是应为这个东西害得我研究了两天 没有这个的话 程序运行一会儿就提示崩溃了 //因为垃圾回收期把我的回调函数当垃圾收了 所以运行程序的时候 一会儿就提示我 一个垃圾的回调导致程序崩溃 //在非托管调用托管的时候 必须保持托管代码的或活动性 大概就这个意思 反正就是被收废品的收了、害的我用.net3.5用其他方式设置Hook public int MouseHookProcedure(int nCode, IntPtr wParam, IntPtr lParam) {//这个就是回调函数了 if (nCode >= 0 && HooKMouseEvent != null) {//先判断是否事件被绑定(感觉有点多余的判断 丫的我不在上面绑定 我写Hook干嘛) //话说是把内存的什么什么转换成结构体 MouseLLInfo mouseInfo = (MouseLLInfo)Marshal.PtrToStructure(lParam, typeof(MouseLLInfo)); Btn btn = Btn.None; //自己定义的一个枚举 里面只有三个值 if (wParam == (IntPtr)WM_LBUTTONDOWN) { //如果左键被点下 btn = Btn.LeftDowm; } else if (wParam == (IntPtr)WM_RBUTTONUP) { //如果右键被抬起 btn = Btn.RightUp; } //好吧 我就不知道当时我怎么想的 在Hook里面获取的坐标 有负数的现象 所以在那边 我没用这个坐标 MouseInfoEventArys e = new MouseInfoEventArys(btn, mouseInfo.pt.x, mouseInfo.pt.y); HooKMouseEvent(this, e);//触发绑定到这个上面的事件 } return CallNextHookEx(handleOfHook, nCode, wParam, lParam);//继续下一个钩子 } public bool SetMouseHook() { //设置Hook if (isSet) {//如果已经设置了 就不要设置啦、、、 return false; } HookProc MouseCallBack = new HookProc(MouseHookProcedure); handleOfHook = SetWindowsHookEx(WH_MOUSE_LL, MouseCallBack, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); if (handleOfHook != 0) {//如果设置成功、、 gc = GCHandle.Alloc(MouseCallBack);//这个就是那个什么什么、、然后我的回调就不会被收废品的拣去了 isSet = true; return true; } return false; } public bool UnLoadMouseHook() { if (!isSet) {//如果装都没有装那么久不要卸载啦、、 return false; } if (UnhookWindowsHookEx(handleOfHook)) { gc.Free();//将回调释放掉、、 isSet = false; return true; } return false; } } public enum Btn//我只感觉到这三个有用、(应该是两个 左键点下 右键抬起) { LeftDowm, RightUp, None } public class MouseInfoEventArys {//话说定义事件的时候都是这么写的 所以我也弄一个内出来保存事件参数 private int x;//坐标 多余的后来才发现 鼠标慢慢贴近屏幕边缘的时候 3 2 1 0 -1 、、丫的 负数都出来了 public int X { get { return x; } } private int y;//坐标 public int Y { get { return y; } } private Btn mBtn; public Btn MBtn { get { return mBtn; }//鼠标的情况 } public MouseInfoEventArys(Btn btn,int x,int y) {//构造器 mBtn = btn; this.x = x; this.y = y; } }}
    2013-12-22下载
    积分:1
  • xml文件转换成csv文件
    实现数据格式转换,对xml数据文件进行解析,把数据保存到csv文件里。
    2014-09-04下载
    积分:1
  • C# 进程间通信(IPC, Inter-Process Communication) 实例源码
    实现了 不同winform窗体之间 发送消息,即:不同的exe应用程序之间的通信
    2019-07-10下载
    积分:1
  • http post工具源码
    http post工具源码
    2015-06-30下载
    积分:1
  • xml 加密 解密 文件内容
    xml 加密 解密 文件内容
    2014-03-15下载
    积分:1
  • Winform treeview控件设计及应用源码
    C#winform 控件开发 TreeView实例
    2017-04-28下载
    积分:1
  • C# 7.0 in a Nutshell果壳C#.pdf
    C# 7.0 in a Nutshell果壳C#.pdf
    2020-03-27下载
    积分:1
  • 696516资源总数
  • 106571会员总数
  • 2今日下载