Winform中label的背景如何在progressBar上透明呢? winformlabelprogressbar 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢回复.不行的..第一个就是用的这种方法..完全无效果,父容器Parent都设置了. 你那个progressbar是什么背景呢?设置成一样的可以吗 谢谢回复不可以,必须label背景透明才行啊,progressbar进度条前进的时候颜色就变了. 如果要在进度条上写文字,可以扩展一个派生类自己画,不用label。看下这个例子: public partial class Form1 : Form { public Form1() { InitializeComponent(); var progressBar = new MyProgressBar() { Location = new Point(20, Bottom - 150), Size = new Size(Width - 60, 50), Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom }; this.Controls.Add(progressBar); var timer = new Timer {Interval = 150}; timer.Tick += (s, e) => progressBar.Value = progressBar.Value%100 + 1; timer.Start(); } private void Form1_Load(object sender, EventArgs e) { } } public class MyProgressBar : ProgressBar { public MyProgressBar() { SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); } protected override void OnPaint(PaintEventArgs e) { Rectangle rect = ClientRectangle; Graphics g = e.Graphics; ProgressBarRenderer.DrawHorizontalBar(g, rect); rect.Inflate(-3, -3); if (Value > 0) { var clip = new Rectangle(rect.X, rect.Y, (int) ((float) Value/Maximum*rect.Width), rect.Height); ProgressBarRenderer.DrawHorizontalChunks(g, clip); } string text = Value + "%"; using (var font = new Font(FontFamily.GenericSerif, 20)) { SizeF sz = g.MeasureString(text, font); var location = new PointF(rect.Width/2 - sz.Width/2, rect.Height/2 - sz.Height/2 + 2); g.DrawString(text, font, Brushes.Red, location); } } } http://www.codeproject.com/Articles/33971/ProgressBar-with-Percentage 设置Label的width,先设置一个总长度,再按完成百分比改变width的长度 android:background="@null",这样就可以实现透明了,用transparent的话会有一层白的,不是完全透明的 C#中istView 隐藏一列,但是拖得的话又出来了 寻求TCP防火墙、路由器打洞的完整方案和代码 (急求)SQLDMO在C#中的差异备份还原问题 谁能给我解释一下? 关于使用XML序列化的问题 asp.net2.0 文件上传进度条及上传速率实现 如何开一个像阿里爸爸的贸易通的软件 求助WebService中应用程序池w3wp.exe内存占用 (十万火急!在线等)选定的文件不是有效的visual studio解决方案 怎么样吧一个String转换成一个整数。 请问高手们:如何调用FoxMail并附加附件 安装C#编写的软件提示“KB893802v2”安装程序错误
不行的..第一个就是用的这种方法..完全无效果,父容器Parent都设置了.
不可以,必须label背景透明才行啊,progressbar进度条前进的时候颜色就变了.
{
public Form1()
{
InitializeComponent(); var progressBar = new MyProgressBar()
{
Location = new Point(20, Bottom - 150),
Size = new Size(Width - 60, 50),
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom
};
this.Controls.Add(progressBar); var timer = new Timer {Interval = 150};
timer.Tick += (s, e) => progressBar.Value = progressBar.Value%100 + 1;
timer.Start();
} private void Form1_Load(object sender, EventArgs e)
{
}
} public class MyProgressBar : ProgressBar
{
public MyProgressBar()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
} protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect = ClientRectangle;
Graphics g = e.Graphics; ProgressBarRenderer.DrawHorizontalBar(g, rect);
rect.Inflate(-3, -3);
if (Value > 0)
{
var clip = new Rectangle(rect.X, rect.Y, (int) ((float) Value/Maximum*rect.Width), rect.Height);
ProgressBarRenderer.DrawHorizontalChunks(g, clip);
} string text = Value + "%";
using (var font = new Font(FontFamily.GenericSerif, 20))
{
SizeF sz = g.MeasureString(text, font);
var location = new PointF(rect.Width/2 - sz.Width/2, rect.Height/2 - sz.Height/2 + 2);
g.DrawString(text, font, Brushes.Red, location);
}
}
}