当前位置:网站首页>C smoothprogressbar custom progress bar control
C smoothprogressbar custom progress bar control
2022-04-23 07:54:00 【Dake mountain man】
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace SmoothProgressBar
{
/// <summary>
/// UserControl1 Summary description of .
/// </summary>
public class SmoothProgressBar : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variables .
/// </summary>
private System.ComponentModel.Container components = null;
public SmoothProgressBar()
{
// The call is Windows.Forms Required by form designer .
InitializeComponent();
// TODO: stay InitComponent Add any initialization after call
}
/// <summary>
/// Clean up all the resources in use .
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Code generated by component designer
/// <summary>
/// The designer supports the required methods - Don't use the code editor
/// Modify the content of this method .
/// </summary>
private void InitializeComponent()
{
//
// SmoothProgressBar
//
this.Name = "SmoothProgressBar";
}
#endregion
int min = 0; // Minimum value for progress range
int max = 100; // Maximum value for progress range
int val = 0; // Current progress
Color BarColor = Color.Blue; // Color of progress meter
protected override void OnResize(EventArgs e)
{
// Invalidate the control to get a repaint.
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush brush = new SolidBrush(BarColor);
float percent = (float)(val - min) / (float)(max - min);
Rectangle rect = this.ClientRectangle;
// Calculate area for drawing the progress.
rect.Width = (int)((float)rect.Width * percent);
// Draw the progress meter.
g.FillRectangle(brush, rect);
// Draw a three-dimensional border around the control.
Draw3DBorder(g);
// Clean up.
brush.Dispose();
g.Dispose();
}
public int Minimum
{
get
{
return min;
}
set
{
// Prevent a negative value.
if (value < 0)
{
min = 0;
}
// Make sure that the minimum value is never set higher than the maximum value.
if (value > max)
{
min = value;
min = value;
}
// Ensure value is still in range
if (val < min)
{
val = min;
}
// Invalidate the control to get a repaint.
this.Invalidate();
}
}
public int Maximum
{
get
{
return max;
}
set
{
// Make sure that the maximum value is never set lower than the minimum value.
if (value < min)
{
min = value;
}
max = value;
// Make sure that value is still in range.
if (val > max)
{
val = max;
}
// Invalidate the control to get a repaint.
this.Invalidate();
}
}
public int Value
{
get
{
return val;
}
set
{
int oldValue = val;
// Make sure that the value does not stray outside the valid range.
if (value < min)
{
val = min;
}
else if (value > max)
{
val = max;
}
else
{
val = value;
}
// Invalidate only the changed area.
float percent;
Rectangle newValueRect = this.ClientRectangle;
Rectangle oldValueRect = this.ClientRectangle;
// Use a new value to calculate the rectangle for progress.
percent = (float)(val - min) / (float)(max - min);
newValueRect.Width = (int)((float)newValueRect.Width * percent);
// Use an old value to calculate the rectangle for progress.
percent = (float)(oldValue - min) / (float)(max - min);
oldValueRect.Width = (int)((float)oldValueRect.Width * percent);
Rectangle updateRect = new Rectangle();
// Find only the part of the screen that must be updated.
if (newValueRect.Width > oldValueRect.Width)
{
updateRect.X = oldValueRect.Size.Width;
updateRect.Width = newValueRect.Width - oldValueRect.Width;
}
else
{
updateRect.X = newValueRect.Size.Width;
updateRect.Width = oldValueRect.Width - newValueRect.Width;
}
updateRect.Height = this.Height;
// Invalidate the intersection region only.
this.Invalidate(updateRect);
}
}
public Color ProgressBarColor
{
get
{
return BarColor;
}
set
{
BarColor = value;
// Invalidate the control to get a repaint.
this.Invalidate();
}
}
private void Draw3DBorder(Graphics g)
{
int PenWidth = (int)Pens.White.Width;
g.DrawLine(Pens.DarkGray,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top));
g.DrawLine(Pens.DarkGray,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
}
}
}
版权声明
本文为[Dake mountain man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230625378406.html
边栏推荐
- 中间人环境mitmproxy搭建
- Unity get real geographic map application terrain notes
- About unity to obtain links related to the transformation of real geographic maps into 3D
- Electronic builder package error: proxyconnect TCP: Dial TCP: 0: connectex
- Daily question | fear dominated by reverse linked list
- 第四章 无形资产
- Scrapy modifies the time in the statistics at the end of the crawler as the current system time
- 利用Lambda表达式解决c#文件名排序问题(是100大还是11大的问题)
- C SVG path parser of xamarin version
- electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
猜你喜欢

VBA calls SAP RFC to read & write data

C # control the camera, rotate and drag the observation script (similar to scenes observation mode)

How does Apache Hudi accelerate traditional batch mode?

对复杂字典Dictionary&lt;T1,T2&gt;排序问题
![[NLP notes] preliminary study on CRF principle](/img/8c/2717aeee2e75bdae97d2bacd362e53.png)
[NLP notes] preliminary study on CRF principle

Houdini流体>>粒子流体导出到unity笔记

VBA调用SAP RFC实现数据读取&写入

Apache Hudi 如何加速传统的批处理模式?
![MySQL8. 0 installation / uninstallation tutorial [window10 version]](/img/9c/1acf153b410f0d2eb6a23dcdbabb88.png)
MySQL8. 0 installation / uninstallation tutorial [window10 version]

linux下mysql数据库备份与恢复(全量+增量)
随机推荐
C operation registry full introduction
常用Markdown语法学习
TA notes of Zhuang understand (zero) < bedding and learning methods >
.NET 5 的新功能 What‘s new in .NET 5
MySQL in window10 version does not work after setting remote access permission
庄懂的TA笔记(六)<FakeEnvReflect && 生锈,锈迹效果>
C# SmoothProgressBar自定义进度条控件
electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
unity 屏幕自适应
事件管理之一
关于U盘数据提示RAW,需要格式化,数据恢复笔记
How to present your digital portfolio: suggestions from creative recruiters
命令行参数传递库argparse的使用
Dropping Pixels for Adversarial Robustness
Common markdown grammar learning
c#读取INI文件和向ini文件写入数据
SampleCameraFilter
Unity screen adaptation
平面定义-平面方程
系统与软件安全研究(四)