111,098
社区成员




public class PercentProgressBar : ProgressBar
{
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_PAINT = 15;
if (m.Msg == WM_PAINT && this.Value > 0)
{
using (Graphics g = this.CreateGraphics())
{
string percentage = this.Tag.ToString();
StringFormat sf = new StringFormat();
sf.Alignment = sf.LineAlignment = StringAlignment.Center;
g.DrawString(percentage, SystemFonts.DefaultFont, Brushes.Red, this.ClientRectangle, sf);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 5000; i++)
{
percentProgressBar1.Tag = ((double)i / 5000 * 100).ToString("f2");
percentProgressBar1.Value = Convert.ToInt32((double)i / 5000 * 100);
Thread.Sleep(1);
}
}
private void button3_Click(object sender, EventArgs e)
{
RegionControl(l_pshow, "100%");
}
private void RegionControl(Control control, string txt)
{
GraphicsPath gp = new GraphicsPath();
gp.AddString(txt, new FontFamily("宋体"), (int)FontStyle.Bold, 16, control.ClientRectangle, new StringFormat(StringFormatFlags.NoWrap));
control.Region = new Region(gp);
}