简体   繁体   English

控制不透明度

[英]Opacity on Control

是否可以使控件半透明?

The direct answer to your question is 'No'.您问题的直接答案是“否”。

WinForms supports Translucency at the Form level ( Form.Opacity ), but not controls. WinForms 在表单级别 ( Form.Opacity ) 支持半透明,但不支持控件。 In cases this was important, I have used layered forms.在这很重要的情况下,我使用了分层表单。

If this feature is important and changing frameworks is an option, WPF does support translucent controls.如果此功能很重要并且可以选择更改框架,则 WPF 确实支持半透明控件。

If the control supports transparent backgrounds, you can use Color.FromArgb() to set a translucent color:如果控件支持透明背景,可以使用Color.FromArgb()设置半透明颜色:

button1.BackColor = Color.FromArgb(100, Color.Red);

Depending on how you want this to work, you would vary the alpha value (to between 0 and 255).根据您希望它如何工作,您可以改变 alpha 值(在 0 到 255 之间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM