質問

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