P1C Unrelated
P1C Unrelated

Reputation: 221

Trackback controls Alpha value for color

I have a textbox which I'm using its backcolor as a color preview, and a trackbar which controls the alpha of that color. I'm using the following code:

private void trackAlpha_ValueChanged(object sender, EventArgs e) {
    colorPreview.BackColor = Color.FromArgb(trackAlpha.Value, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B);
}

Turns out that scrolling the alpha will have no effect on the preview whatsoever.

Any ideas on why this could be happening?

Upvotes: 0

Views: 649

Answers (1)

Dan
Dan

Reputation: 9847

WinForms Controls do support an alpha channel, but not by default. For the control that you want to have a translucent back color, you must call the SetStyle method:

this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

The method is protected, so you'll have to inherit from the control you want and call it in the constructor or something. This control will be whatever colorPreview is referring to.

Upvotes: 1

Related Questions