如何在winforms上绘制我自己的进度条?
Yoyo专家! 我的Windowsform(不是WPF)上有几个进度条,我想为每个使用不同的颜色。 我怎样才能做到这一点? 我用Google搜索,发现我必须创建自己的控件。 但我不知道如何做到这一点。 任何的想法? 例如progressBar1绿色,progressbar2红色。
编辑:哦,我想解决这个问题,而不删除Application.EnableVisualStyles(); 线,因为它会抬起我的形状:/
是的,创建自己的。 一个粗略的草案,让你80%,根据需要修饰:
using System; using System.Drawing; using System.Windows.Forms; class MyProgressBar : Control { public MyProgressBar() { this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, false); Maximum = 100; this.ForeColor = Color.Red; this.BackColor = Color.White; } public decimal Minimum { get; set; } // fix: call Invalidate in setter public decimal Maximum { get; set; } // fix as above private decimal mValue; public decimal Value { get { return mValue; } set { mValue = value; Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { var rc = new RectangleF(0, 0, (float)(this.Width * (Value - Minimum) / Maximum), this.Height); using (var br = new SolidBrush(this.ForeColor)) { e.Graphics.FillRectangle(br, rc); } base.OnPaint(e); } }
- 加载X509Certificate结果exceptionCryptographicException“找不到原始签名者”
- 如何在C#中将值从form2 datagridview复制/传输到form1 datagridview?
- 如何防止事件导致自己的事件在C#中触发?
- Asp:FileUpload编辑“未选择文件”消息
- Winforms ComboBox SelectedItem更改不会影响BindingSource
- 在C#代码后面的页面中添加换行符
- 使用MSIEnumRelatedProducts和MSIGetProductInfo的MSI Interop
- 如何在Xamarin中的视图控制器之间传递数据
- 增加字母表