I am looking to have a textlabel fade in and out on a button press. I notice that textlabel does not have an opacity parameter. Is there another way that I can achieve the desired result ?
Asked
Active
Viewed 3,825 times
4
-
[Label](http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx) you mean? – Victor Zakharov Mar 19 '13 at 15:22
-
1In short, it's quite complex, but here is a link that provides a fully functional example (http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/ded003e3-ab35-4c23-b645-af7f82df57f0). – Mike Perrenoud Mar 19 '13 at 15:26
4 Answers
2
There is no support for Control
Opacity in Winform
.
In .Net Framework only Form
is capable of showing opacity property, Controls
on the Form have same Opacity
to that of parent Form
.

Parimal Raj
- 20,189
- 9
- 73
- 110
1
WinForms do not support this.
You could use a Panel control with text on it and use a fade effect by swapping colors in a timer event.
-
It's not necessarily true that it's not supported (http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/ded003e3-ab35-4c23-b645-af7f82df57f0). – Mike Perrenoud Mar 19 '13 at 15:27
0
To fade a monochrome text label in/out, I have successfully used a timer to read the ForeColor of the label, scale the R component as required, then set a new ForeColour. E.g. to fade out:
private void LabelFader_Tick(object sender, EventArgs e)
{
var colour = myLabel.ForeColor;
byte cR = colour.R;
if (cR < 210) // Set whatever limit you want, 0-255
cR++; // cR-- to fade in
else
labelFader.Stop();
myLabel.ForeColor = Color.FromArgb(255, cR, cR, cR);
}

Skyfish
- 119
- 2
- 4
-5
I guess, you are looking for something like that:
private void button1_Click(object sender, EventArgs e) {
if (label1.Visible) label1.Visible = false;
else label1.Visible = true;
}

user2186640
- 1
- 1