문제

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