Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top