ProgressBar的问题

zzyhuian06142 2007-03-23 04:32:25
请问如何做成像我们在装软件的时候,有滚动条的,并能显示出百分比的呢
能给我代码看看吗?
谢谢!
...全文
207 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
桃子 2008-02-19
  • 打赏
  • 举报
回复
我也标记下
bigrongshu 2007-03-23
  • 打赏
  • 举报
回复
版内搜索一下“进度条",搞定
jjyjjyjjy 2007-03-23
  • 打赏
  • 举报
回复
mark,做个标记
Red_angelX 2007-03-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace GameProcessBar
{
public partial class GameProcessBar : UserControl
{
public GameProcessBar()
{
InitializeComponent();
}

int min = 0;
int max = 100;
int val = 0;
Image im;


protected override void OnResize(EventArgs e)
{
this.Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{
if (im == null)
im = BackImage.BackgroundImage;

this.BackgroundImage = im;

SolidBrush myBrush = new SolidBrush(Color.GhostWhite);
Graphics g = e.Graphics;
float percent = (float)(val - min) / (max - min);
Rectangle rect = this.ClientRectangle;

rect.Width = (int)((float)rect.Width * percent);

//g.DrawImage(im,rect,rect,GraphicsUnit.Pixel);
g.FillRectangle(myBrush, rect);

//int mini = (max - val) / 60;
//int sec = (max - val) % 60;
//string text = string.Format("{0} 分 {1} 秒", mini, sec);
//Font font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
//g.DrawString(text, font, Brushes.Black, 140, 5);


Draw3DBorder(g);

myBrush.Dispose();
g.Dispose();
}

public int Minimum
{
get
{
return min;
}
set
{
if (value < 0)
{
min = 0;
}
if (value > max)
{
max = value;
}
min = value;
if (val < min)
{
val = min;
}
this.Invalidate();
}
}

public int Maximum
{
get
{
return max;
}
set
{
if (value < min)
{
min = value;
}
max = value;
if (val > max)
{
val = max;
}
this.Invalidate();
}
}

public int Value
{
get
{
return val;
}
set
{
int oldVal = val;
if (val < min)
{
val = min;
}
else if (val > max)
{
val = max;
}
else
{
val = value;
}

float percent;

Rectangle newValueRect = this.ClientRectangle;
Rectangle oldValueRect = this.ClientRectangle;

percent = (float)(val - min) / (max - min);
newValueRect.Width = (int)((float)newValueRect.Width * percent);

percent = (float)(oldVal - min) / (float)(max - min);
oldValueRect.Width = (int)((float)oldValueRect.Width * percent);

Rectangle updateRect = new Rectangle();

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;

this.Invalidate(updateRect);

int mini = (max - val) / 60;
int sec = (max - val) % 60;
label1.Text = string.Format("{0} 分 {1} 秒", mini, sec);
//我这里画的是时间,要实现百分比可以再这里实现
}
}

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));
}
}
}
Red_angelX 2007-03-23
  • 打赏
  • 举报
回复
百分比...
ProgressBar不能重载,因此只有自己实现一个了
给你看个参考代码

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧