CWinForm自定义进度条控件
继承ProgressBar
public enum TextPosition { Left, Right, Center, Sliding, None } public class BzProgressBar : ProgressBar { private Color channelColor = Color.LightSteelBlue; private Color sliderColor = Color.RoyalBlue; private Color foreBackColor = Color.RoyalBlue; private int channelHeight = 6; private int sliderHeight = 6; private TextPosition showValue = TextPosition.Right; public BzProgressBar() { this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.UserPaint, true); this.ForeColor = Color.White; } [Category("BZ Advance")] public Color ChannelColor { get { return channelColor; } set { channelColor = value; this.Invalidate(); } } [Category("BZ Advance")] public Color SliderColor { get { return sliderColor; } set { sliderColor = value; this.Invalidate(); } } [Category("BZ Advance")] public Color ForeBackColor { get { return foreBackColor; } set { foreBackColor = value; this.Invalidate(); } } [Category("BZ Advance")] public int ChannelHeight { get { return channelHeight; } set { channelHeight = value; this.Invalidate(); } } [Category("BZ Advance")] public int SliderHeight { get { return sliderHeight; } set { sliderHeight = value; this.Invalidate(); } } [Category("BZ Advance")] public TextPosition ShowValue { get { return showValue; } set { showValue = value; this.Invalidate(); } } [Category("BZ Advance")] [Browsable(true)] [EditorBrowsable(EditorBrowsableState.Always)] public override Font Font { get { return base.Font; } set { base.Font = value; } } [Category("BZ Advance")] public override Color ForeColor { get { return base.ForeColor; } set { base.ForeColor = value; } } protected override void OnPaint(PaintEventArgs e) { Graphics graphics = e.Graphics; Rectangle rectChannel = new Rectangle(0, 0, this.Width, channelHeight); using (var brushChannel = new SolidBrush(channelColor)) { if (channelHeight >= sliderHeight) { rectChannel.Y = this.Height - channelHeight; } else { rectChannel.Y = this.Height - ((channelHeight + sliderHeight) / 2); } graphics.Clear(this.Parent.BackColor); graphics.FillRectangle(brushChannel, rectChannel); } double scaleFactor = (((double)this.Value - this.Minimum)) / (((double)this.Maximum - this.Minimum)); int sliderWidth = (int)(this.Width * scaleFactor); Rectangle rectSlider = new Rectangle(0, 0, sliderWidth, SliderHeight); using (var brushSlider = new SolidBrush(sliderColor)) { if (SliderHeight >= channelHeight) { rectSlider.Y = this.Height - sliderHeight; } else { rectSlider.Y = this.Height - (sliderHeight + channelHeight) / 2; } if (sliderWidth > 1) { graphics.FillRectangle(brushSlider, rectSlider); } if (ShowValue != TextPosition.None) { DrawValueText(graphics, sliderWidth, rectSlider); } } base.OnPaint(e); } /// /// 显示进度百分比 /// /// /// /// private void DrawValueText(Graphics graphics, int sliderWidth, Rectangle rectSlider) { string text = this.Value.ToString() + "%"; var textSize = TextRenderer.MeasureText(text, this.Font); var rectText = new Rectangle(0, 0, textSize.Width, textSize.Height + 2); using (var brushText = new SolidBrush(this.ForeColor)) using (var brushTextBack = new SolidBrush(this.ForeBackColor)) using (var textFormat = new StringFormat()) { switch (showValue) { case TextPosition.Left: rectText.X = 0; textFormat.Alignment = StringAlignment.Near; break; case TextPosition.Right: rectText.X = this.Width - textSize.Width; textFormat.Alignment = StringAlignment.Far; break; case TextPosition.Center: rectText.X = (this.Width - textSize.Width) / 2; textFormat.Alignment = StringAlignment.Center; break; case TextPosition.Sliding: rectText.X = sliderWidth - textSize.Width; textFormat.Alignment = StringAlignment.Center; using (var brushClear = new SolidBrush(this.Parent.BackColor)) { var rect = rectSlider; rect.Y = rectText.Y; rect.Height = rect.Height; graphics.FillRectangle(brushClear, rect); } break; default: break; } graphics.FillRectangle(brushTextBack, rectText); graphics.DrawString(text, this.Font, brushText, rectText, textFormat); } } }
2021苹果秋季发布会预告,多款新品9月14日见?九月已经过去几天了,距离2021苹果秋季发布会可能不到10天,尽管该公司尚未发出正式邀请,但多数迹象都指向9月中旬的一场发布会,届时iPhone13AppleWatch7和AirP
助听器戴久了必须永久依赖吗?许多人担心助听器戴上以后摘不下来,害怕对助听器产生依赖。应该承认,的确有一部分使用者一旦拥有便再也离不开助听器。问题是,为什么会产生这种现象?如果不是强迫,正常听力的人不会戴用助听
助听器突然没有声音了,怎么办?您好!助听器没有声音,可能有这几种情况,可以自己先排查一下助听器电池没电,更换新电池再试一次助听器出声孔被堵塞,将导声管拔下试听一下,有声,说明出声孔堵塞,检查一下耳背机的耳塞导声
在今日头条写作中,为活跃度而阅读文章,你是真正在认真阅读吗?凡自己感觉有份量的新闻也好,评论也好,我都用心去阅读,有时还带着深厚的感情去阅读,喜怒哀乐全在其中。我觉得认真读完的很少,就拿我自己来说,我的文章最短的1500字,自己认真看都是两
想买一辆1020万的新能源汽车,有什么好的推荐?1020万这个价格区间非常广泛,各个品牌的都有相关产品,比如长城的欧拉好猫续航500,外观比较萌内饰也很不错,女孩子肯定特别喜欢。还有广汽埃安y,空间大,后排想象不到的大。也是续航
推荐系统有什么危害?这是一个非常好的问题,在当前很多大型互联网平台都在纷纷使用推荐系统的大背景下,了解推荐系统的优缺点也是有必要的,普通人在了解推荐系统的过程中,也可以根据自身的需要来训练推荐系统,以
廉价的小米再创奇迹智能手表销量超越苹果苹果将在9月下旬发布新一代AppleWatchSeries7,但在发布之前,小米已经超越苹果成为全球最大智能手表制造商。尽管AppleWatchSeries7将采用全新设计,有可能
4G芯片涨价转转5G普及不同步,新兴市场4G手机需求旺5G高速发展下,4G芯片的价格反而在上涨?得益于手机厂商运营商等多方推动,5G已成为拉动手机市场出货量增长的主要动力,但4G手机尚未退出主流舞台,不过其芯片生产线却多数被5G分走,
为什么你会选择华为手机?好用耐用用习惯了不用。性价比不行我用手机的历史,现在看来都是以手机的性价比为唯一标准。买手机就是买手机,不打任何政治标签。2015年前,一直用联想手机,当时中国四大手机的旗帜是联想
苹果笔记本电脑有什么好?朋友您好,首先很高兴回答您的问题!一苹果笔记本优点1苹果笔记本外观精致时尚,经典的银白色的外观充满著给刚,轻薄便携,手感出众。2苹果笔记本配备intel芯片,并且可以相容windo
没有一家手机厂商愿意为了全面屏手机,放弃前置摄像头吗?为什么?放弃前置镜头并不是一个很明智的做法!手机前置镜头与屏幕的优先级肯定是屏幕,但是并不能为了适应屏幕形态就取消前置镜头!下面分为几点来分析!前置镜头功能性一般的前置镜头都是用来自拍的,