当前位置:编程学习 > C#/ASP.NET >>

Winform中label的背景如何在progressBar上透明呢?

label在progressbar上显示,背景透明,只显示文字.怎么实现呢?
能搜索到的各种方法都试验了,统统无效啊,望高手指教. winform label progressbar --------------------编程问答-------------------- label的BackColor设为Transparent --------------------编程问答--------------------
引用 1 楼 rtdb 的回复:
label的BackColor设为Transparent

谢谢回复.
不行的..第一个就是用的这种方法..完全无效果,父容器Parent都设置了. --------------------编程问答--------------------  你那个progressbar是什么背景呢?设置成一样的可以吗 --------------------编程问答--------------------
引用 3 楼 u011129454 的回复:
 你那个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的话会有一层白的,不是完全透明的 --------------------编程问答-------------------- 高人 很多呀
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,