我試圖讓一個usercontrol充當進度條。據我所知,我需要在舊版本的頂部繪製一個新的條形碼,並根據完成的百分比增加它的大小。我有下面的代碼,但不幸的是,綠色的酒吧是100%,即使我設置控制初始化時百分比屬性爲0%。我假設我做了一個愚蠢的監督,但我不能看到它,任何幫助將不勝感激。謝謝。用戶控制進度條
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace CustomPbar
{
public partial class Pbar : UserControl
{
private int PercentageValue;
public int Percentage
{
get { return PercentageValue;}
set
{
PercentageValue = value;
this.Invalidate();
}
}
public Pbar()
{
InitializeComponent();
Percentage = 0;
using(GraphicsPath path = new GraphicsPath())
{
path.StartFigure();
// top left arc
path.AddArc(0, 0, (10), (10), 180, 90);
//rect, 180, 90);
// top right arc
path.AddArc(((this.Width) - (10)), 0, (10), (10), 270, 90);
// bottom right arc
path.AddArc(((this.Width) - (10)), ((this.Height) - (10)), (10), (10), 0, 90);
// bottom left arc
path.AddArc(0, ((this.Height) - (10)), (10), (10), 90, 90);
path.CloseFigure();
this.Region = new Region(path);
this.BackColor = SystemColors.ControlLight;
this.BackgroundImage = new Bitmap(@"c:\users\FrazMan\Desktop\pb1.bmp");
this.BackgroundImageLayout = ImageLayout.Stretch;
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle rect = new Rectangle(0, 0, ((this.Width)*((Percentage)/100)), this.Height);
using (GraphicsPath gp = new GraphicsPath())
{
gp.StartFigure();
// top left arc
gp.AddArc(0, 0, (10), (10), 180, 90);
// top right arc
gp.AddArc(((rect.Width) - (10)), 0, (10), (10), 270, 90);
// bottom right arc
gp.AddArc(((rect.Width) - (10)), ((rect.Height) - (10)), (10), (10), 0, 90);
// bottom left arc
gp.AddArc(0, ((rect.Height) - (10)), (10), (10), 90, 90);
gp.CloseFigure();
SolidBrush greenBrush = new SolidBrush(Color.Green);
e.Graphics.FillPath(greenBrush, gp);
greenBrush.Dispose();
}
using(Graphics Draw = this.CreateGraphics())
{
Draw.DrawString(Percentage.ToString() + "%", ProgressBar.DefaultFont, Brushes.Black, new PointF((this.Width/2) - ((Draw.MeasureString(Percentage.ToString() + "%", ProgressBar.DefaultFont)).Width/2.0F),
(this.Height/2) - ((Draw.MeasureString(Percentage.ToString() + "%", ProgressBar.DefaultFont)).Height/2.0F)));
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Refresh();
}
}
}
你'Percentage.set'應該無效()控制 – 2012-03-14 13:08:35
@HenkHolterman嗨,我改變了我的原代碼(見上文),但其仍無法正常工作,我只是得到一個堅實的綠色酒吧,沒有百分比等。 – 2012-03-14 13:14:01