/// <summary> /// 创建进度条 /// </summary> /// <param name="dtSource">数据源,列0/1/2/:ID,Name,ColorStr</param> void CreateBar(DataTable dtSource) { foreach (Control ctl in this.Controls) { if (ctl is UCStatusBarStandOne) { this.Controls.Remove(ctl);//移除控件 } } int modeType = UCStatusBarParamSet.GetIntValueByID(7401);//进度条模式序号:0/1/2/:默认/标准/圆角矩形 string bColorStr = UCStatusBarParamSet.GetStrValueByID(7402);//进度边框颜色,未设置使用默认色 Color ucbColor = UCStatusBarParamSet.ConvertColorByStr(bColorStr); for (int i = 0; i < dtSource.Rows.Count; i++) { UCStatusBarStandItemBase ucft = CreateBar(modeType, i); ucft.UCBackColor = UCFabCommon.ConvertColorByStr(dtSource.Rows[i][2].ToString()); ucft.UCContext = dtSource.Rows[i][1].ToString(); if (ucbColor != Color.White) { ucft.UCBorderColor = ucbColor; } this.Controls.Add(ucft); Application.DoEvents(); } }
/// <summary> /// 绘制方法 /// </summary> /// <param name="graphics"></param> /// <param name="label"></param> private void DrawRoundRect(Graphics graphics, Control label) { float X = float.Parse(label.Width.ToString()) - 1; float Y = float.Parse(label.Height.ToString()) - 1; PointF[] points = { new PointF(2, 0), new PointF(X - 2, 0), new PointF(X - 1, 1), new PointF(X, 2), new PointF(X, Y - 2), new PointF(X - 1, Y - 1), new PointF(X - 2, Y), new PointF(2, Y), new PointF(1, Y - 1), new PointF(0, Y - 2), new PointF(0, 2), new PointF(1, 1) }; GraphicsPath path = new GraphicsPath(); path.AddLines(points); string colorStr = string.Empty; try { if (label.Tag.ToString() != string.Empty)//如果下列内容 颜色字符串存储在Tag内,便于控件识别,短暂性方法 { colorStr = label.Tag.ToString(); } } catch { //不处理 } Color oc = Color.Blue; if (colorStr != string.Empty)//如果读取到颜色字符串了 { oc = UCStatusBarParamSet.ConvertColorByStr(colorStr); if (oc == Color.White)//如果是白色用默认方法 { oc = Color.Blue; } } Pen pen = new Pen(Color.FromArgb(150, oc), 1); pen.DashStyle = DashStyle.Solid; graphics.DrawPath(pen, path); }