本文整理汇总了C#中System.Windows.Forms.ProgressBarRenderer类的典型用法代码示例。如果您正苦于以下问题:C# ProgressBarRenderer类的具体用法?C# ProgressBarRenderer怎么用?C# ProgressBarRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProgressBarRenderer类属于System.Windows.Forms命名空间,在下文中一共展示了ProgressBarRenderer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: VerticalProgressBar
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace ProgressBarRendererSample
{
public class Form1 : Form
{
private VerticalProgressBar bar1 = new VerticalProgressBar();
private Button button1 = new Button();
public Form1()
: base()
{
this.Size = new Size(500, 500);
bar1.NumberChunks = 30;
button1.Location = new Point(150, 10);
button1.Size = new Size(150, 30);
button1.Text = "Start VerticalProgressBar";
button1.Click += new EventHandler(button1_Click);
Controls.AddRange(new Control[] { button1, bar1 });
}
[STAThread]
public static void Main()
{
// The call to EnableVisualStyles below does not affect
// whether ProgressBarRenderer.IsSupported is true; as
// long as visual styles are enabled by the operating system,
// IsSupported is true.
Application.EnableVisualStyles();
Application.Run(new Form1());
}
// Start the VerticalProgressBar.
private void button1_Click(object sender, EventArgs e)
{
bar1.Start();
}
}
public class VerticalProgressBar : Control
{
private int numberChunksValue;
private int ticks;
private Timer progressTimer = new Timer();
private Rectangle[] progressBarRectangles;
public VerticalProgressBar()
: base()
{
this.Location = new Point(10, 10);
this.Width = 50;
// The progress bar will update every second.
progressTimer.Interval = 1000;
progressTimer.Tick += new EventHandler(progressTimer_Tick);
// This property also calls SetupProgressBar to initialize
// the progress bar rectangles if styles are enabled.
NumberChunks = 20;
// Set the default height if visual styles are not enabled.
if (!ProgressBarRenderer.IsSupported)
{
this.Height = 100;
}
}
// Specify the number of progress bar chunks to base the height on.
public int NumberChunks
{
get
{
return numberChunksValue;
}
set
{
if (value <= 50 && value > 0)
{
numberChunksValue = value;
}
else
{
MessageBox.Show("Number of chunks must be between " +
"0 and 50; defaulting to 10");
numberChunksValue = 10;
}
// Recalculate the progress bar size, if visual styles
// are active.
if (ProgressBarRenderer.IsSupported)
{
SetupProgressBar();
}
}
}
// Draw the progress bar in its normal state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (ProgressBarRenderer.IsSupported)
{
ProgressBarRenderer.DrawVerticalBar(e.Graphics,
ClientRectangle);
this.Parent.Text = "VerticalProgressBar Enabled";
}
else
{
this.Parent.Text = "VerticalProgressBar Disabled";
}
}
// Initialize the rectangles used to paint the states of the
// progress bar.
private void SetupProgressBar()
{
if (!ProgressBarRenderer.IsSupported)
{
return;
}
// Determine the size of the progress bar frame.
this.Size = new Size(ClientRectangle.Width,
(NumberChunks) * (ProgressBarRenderer.ChunkThickness +
(2 * ProgressBarRenderer.ChunkSpaceThickness)) + 6);
// Initialize the rectangles to draw each step of the
// progress bar.
progressBarRectangles = new Rectangle[NumberChunks];
for (int i = 0; i < NumberChunks; i++)
{
// Use the thickness defined by the current visual style
// to calculate the height of each rectangle. The size
// adjustments ensure that the chunks do not paint over
// the frame.
int filledRectangleHeight =
((i + 1) * (ProgressBarRenderer.ChunkThickness +
(2 * ProgressBarRenderer.ChunkSpaceThickness)));
progressBarRectangles[i] = new Rectangle(
ClientRectangle.X + 3,
ClientRectangle.Y + ClientRectangle.Height - 3
- filledRectangleHeight,
ClientRectangle.Width - 6,
filledRectangleHeight);
}
}
// Handle the timer tick; draw each progressively larger rectangle.
private void progressTimer_Tick(Object myObject, EventArgs e)
{
if (ticks < NumberChunks)
{
using (Graphics g = this.CreateGraphics())
{
ProgressBarRenderer.DrawVerticalChunks(g,
progressBarRectangles[ticks]);
ticks++;
}
}
else
{
progressTimer.Enabled = false;
}
}
// Start the progress bar.
public void Start()
{
if (ProgressBarRenderer.IsSupported)
{
progressTimer.Start();
}
else
{
MessageBox.Show("VerticalScrollBar requires visual styles");
}
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:188,代码来源:ProgressBarRenderer
注:本文中的System.Windows.Forms.ProgressBarRenderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论