C#進(jìn)度軸控件分享
當(dāng)執(zhí)行長時(shí)間后臺(tái)處理時(shí),你是否希望軟件給你一個(gè)反饋,讓你了解程序執(zhí)行進(jìn)度。進(jìn)度軸幫你忙,輕松掌握全局動(dòng)態(tài)。你的進(jìn)度你做主!進(jìn)度軸分為橫版和縱版總有一版適合你!
應(yīng)用了事件機(jī)制假如有更好的方法歡迎交流,假如對您有用請頂一下。
載入時(shí)間軸控件
/// <summary> /// 載入時(shí)間軸控件 /// 2015-04-16 /// 吳海龍 /// </summary> public void LoadTimeAxis() { SortedDictionary<string, string> sdict = new SortedDictionary<string, string>(); sdict.Add("1", "讀取配置"); sdict.Add("2", "選擇模板"); sdict.Add("3", "確認(rèn)數(shù)據(jù)"); sdict.Add("4", "生成代碼"); uta = new uctlTimeAxis(sdict,1); uta.lc = new ToolFunction.uctlTimeAxis.TimeAxisClick(SayHello); CommonFunction.AddForm3(splitContainer4.Panel2, uta); }
panel容器中添加控件
/// <summary> /// 項(xiàng)panel容器中添加控件 /// </summary> /// <param name="p">容器panel</param> /// <param name="uc">顯示的usercontrol</param> public static void AddForm3(Panel p, UserControl uc) { p.Controls.Clear(); p.Controls.Add(uc); uc.Dock = DockStyle.Fill; }
初始化縱版界面
/// <summary> /// 初始化垂直進(jìn)度軸 /// 2015-04-15 /// 吳海龍 /// </summary> public void InitVerticalTimeAxis() { try { int TempCenterOfThePieY = CenterOfTheCircleY; using (Graphics g = this.CreateGraphics()) { g.SmoothingMode = SmoothingMode.HighQuality; //使繪圖質(zhì)量最高,即消除鋸齒 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawString("正在執(zhí)行:", f1, Brushes.Black, new PointF(CenterOfTheCircleX, 5)); g.DrawLine(p3, new Point(LineStartX, TempCenterOfThePieY), new Point(LineStartX, (sdict.Keys.Count - 1) * CircleSpace + TempCenterOfThePieY)); foreach (var item in sdict.Keys) { g.FillEllipse(Brushes.Gray, CenterOfTheCircleX - CircleRadius, TempCenterOfThePieY - CircleRadius, CircleRadius * 2, CircleRadius * 2); g.FillEllipse(Brushes.White, CenterOfTheCircleX - PieRadius2, TempCenterOfThePieY - PieRadius2, PieRadius2 * 2, PieRadius2 * 2); g.DrawString(sdict[item], f1, Brushes.DarkGray, new PointF(ItemStartX, TempCenterOfThePieY - ItemFixY)); Label l = new Label(); l.Name = item; l.Location = new Point(ItemStartX,TempCenterOfThePieY - ItemFixY); l.Text = sdict[item]; l.Click +=new EventHandler(l_Click); //l.Click += new EventHandler(l_Click2); this.Controls.Add(l); TempCenterOfThePieY = TempCenterOfThePieY + CircleSpace; } } } catch (Exception exp) { CommonFunction.WriteLog(exp, "繪制失敗"); } }
縱版進(jìn)度軸步進(jìn)方法
/// <summary> /// 垂直步進(jìn)方法 /// /// 2015-04-16 /// 吳海龍 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void SetVerticalStep(object sender, KeyValueEventArgs e) { int TempCenterOfThePieY = CenterOfTheCircleY; if ("" == KeyValueEventArgs.Key) { return; } using (Graphics g = this.CreateGraphics()) { g.SmoothingMode = SmoothingMode.HighQuality; //使繪圖質(zhì)量最高,即消除鋸齒 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; foreach (var item in sdict.Keys) { g.DrawString(sdict[item], f1, Brushes.Green, ItemStartX, TempCenterOfThePieY - ItemFixY); g.DrawEllipse(Pens.Green, CenterOfTheCircleX - CircleRadius, TempCenterOfThePieY - CircleRadius, CircleRadius * 2, CircleRadius * 2); g.DrawLine(p2, new Point(LineStartX, LineStartY), new Point(LineStartX, TempCenterOfThePieY)); g.FillEllipse(Brushes.Green, CenterOfTheCircleX - PieRadius, TempCenterOfThePieY - PieRadius, PieRadius * 2, PieRadius * 2); if (item == KeyValueEventArgs.Key) { break; } TempCenterOfThePieY = TempCenterOfThePieY + CircleSpace; } } }
畫圖屬性字段
/// <summary> /// 藍(lán)色寬2 /// </summary> static Pen p1 = new Pen(Color.Blue, 2); /// <summary> /// 綠色寬3 /// </summary> static Pen p2 = new Pen(Color.Green, 3); /// <summary> /// 灰色寬1 /// </summary> static Pen p3 = new Pen(Color.Gray, 1); /// <summary> /// 微軟雅黑 /// </summary> static Font f1 = new Font("微軟雅黑", 9, FontStyle.Regular); /// <summary> /// 圓心X坐標(biāo) /// </summary> public static int CenterOfTheCircleX = 31; /// <summary> /// 圓心Y坐標(biāo) /// </summary> public static int CenterOfTheCircleY = 46; /// <summary> /// 說明條目X坐標(biāo) /// </summary> public static int ItemStartX = 45; /// <summary> /// 條目X修正量 /// </summary> public static int ItemFixX = -20; /// <summary> /// 條目Y修正量 /// </summary> public static int ItemFixY = 10; public static Point CenterOfThePie = new Point(CenterOfTheCircleX, CenterOfTheCircleY); /// <summary> /// 命中Pie半徑 /// </summary> public static int PieRadius = 6; /// <summary> /// 白點(diǎn)Pie半徑 /// </summary> public static int PieRadius2 = 8; /// <summary> /// 圓半徑 /// </summary> public static int CircleRadius = 9; /// <summary> /// 圓心距 /// </summary> public static int CircleSpace = 80; /// <summary> /// 軸X起點(diǎn) /// </summary> public static int LineStartX = CenterOfTheCircleX; /// <summary> /// 軸Y起點(diǎn) /// </summary> public static int LineStartY = CenterOfTheCircleY; /// <summary> /// 內(nèi)部Key定義 /// </summary> public static string Key = ""; /// <summary> /// 繪圖事件 /// </summary> public event EventHandler<KeyValueEventArgs> KeyValueChangeEventHandler; public delegate void LabelClickEventHandler(object sender, LabelClickEventArgs e); //public event LabelClickEventHandler<LabelClickEventArgs> ; public delegate void TimeAxisClick(); public TimeAxisClick lc = null; public delegate void TimeAxisClick2(string labelName); public TimeAxisClick2 lc2 = null; /// <summary> /// 流程字典 /// </summary> public static SortedDictionary<string, string> sdict = new SortedDictionary<string, string>(); /// <summary> /// 水平標(biāo)示 /// </summary> private static readonly int HorizontalTimeAxis = 0; /// <summary> /// 垂直標(biāo)志 /// </summary> private static readonly int VerticalTimeAxis = 1; /// <summary> /// 繪制標(biāo)志,0為水平;1為垂直。 /// </summary> public static int TimeAxisModle = 0;
構(gòu)造方法
#region 構(gòu)造方法 public uctlTimeAxis() { InitializeComponent(); } public uctlTimeAxis(SortedDictionary<string, string> s) { InitializeComponent(); if (sdict != null) { sdict = s; } } public uctlTimeAxis(SortedDictionary<string, string> s, int model) { InitializeComponent(); if (sdict != null) { sdict = s; TimeAxisModle = model; if (HorizontalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler<KeyValueEventArgs>(SetHorizontalStep); } else if (VerticalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler<KeyValueEventArgs>(SetVerticalStep); } } } #endregion
Key值轉(zhuǎn)變
/// <summary> /// Key值轉(zhuǎn)變 /// </summary> public class KeyValueEventArgs : EventArgs { public static string Key = ""; public KeyValueEventArgs(string s) { Key = s; } }
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- C#中常使用進(jìn)度條的代碼
- asp.net(c#)開發(fā)中的文件上傳組件uploadify的使用方法(帶進(jìn)度條)
- Android文件下載進(jìn)度條的實(shí)現(xiàn)代碼
- 6款新穎的jQuery和CSS3進(jìn)度條插件推薦
- C#控制臺(tái)輸出進(jìn)度和百分比的實(shí)例代碼
- c#進(jìn)度條 progressBar 使用方法的小例子
- C# cmd中修改顯示(顯示進(jìn)度變化效果)的方法
- c#根據(jù)文件大小顯示文件復(fù)制進(jìn)度條實(shí)例
- android自定義進(jìn)度條漸變色View的實(shí)例代碼
- Jquery Uploadify上傳帶進(jìn)度條的簡單實(shí)例
- C# Winform下載文件并顯示進(jìn)度條的實(shí)現(xiàn)代碼
- Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
- 基于jQuery實(shí)現(xiàn)網(wǎng)頁進(jìn)度顯示插件
- php上傳文件并顯示上傳進(jìn)度的方法
- python下載文件時(shí)顯示下載進(jìn)度的方法
相關(guān)文章
C# AE之返回上一級(jí)和下一級(jí)的實(shí)戰(zhàn)操作
這篇文章主要介紹了C# AE之返回上一級(jí)和下一級(jí)的實(shí)戰(zhàn)操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01WinForm實(shí)現(xiàn)狀態(tài)欄跑馬燈效果的方法示例
這篇文章主要介紹了WinForm實(shí)現(xiàn)狀態(tài)欄跑馬燈效果的方法,涉及WinForm控件結(jié)合時(shí)間函數(shù)動(dòng)態(tài)操作元素屬性的相關(guān)技巧,需要的朋友可以參考下2017-07-07C# 中的IComparable和IComparer的使用及區(qū)別
這篇文章主要介紹了C# 中的IComparable和IComparer的使用及區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01C#中數(shù)組、ArrayList、List、Dictionary的用法與區(qū)別淺析(存取數(shù)據(jù))
在工作中經(jīng)常遇到C#數(shù)組、ArrayList、List、Dictionary存取數(shù)據(jù),但是該選擇哪種類型進(jìn)行存儲(chǔ)數(shù)據(jù)呢?很迷茫,今天小編抽空給大家整理下這方面的內(nèi)容,需要的朋友參考下吧2017-02-02C#命令行參數(shù)解析庫System.CommandLine使用
System.CommandLine是一個(gè)基于.Net Standard 2.0的命令行參數(shù)解析庫,該項(xiàng)目還是屬于beta狀態(tài),期待以后的正式版本,文章通過示例代碼給大家介紹了System.CommandLine使用講解,感興趣的朋友一起看看吧2021-06-06