如何从C#中的WinForm.Opacity中排除控件 [英] how to exclude control from a WinForm.Opacity in C#

查看:55
本文介绍了如何从C#中的WinForm.Opacity中排除控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将其不透明度设置为50%的表单,如下所示:

I have a form that i set it's Opacity as 50% like this:

this.Opacity = 0.5D; <--this==Form

我的问题是表单上的所有内容的不透明度均为50%

My problem is that everything that on the form is with an Opacity of 50%

我在表单上有两个按钮,我希望它们不透明.

I have two buttons on the form and I want them without Opacity.

我知道 this.Opacity 包括所有控件,并且出于某种原因,图形也包括在内

I know that this.Opacity included all Controls and for some reason the graphics too

我的问题是,如何排除控件的不透明度?

My question is, How to Exclude the Opacity of the controls?

示例图片:

谢谢!

推荐答案

由于 Control 不具有 Opacity 属性,而且大多数控件没有支持透明颜色,那么可行的解决方案可以是:

Since Control doesn't have Opacity property and plus that, most of the controls doesn't support transparent colors, then a working solution can be this:

  1. 创建一个名为 MainForm Form ,然后放置将要排除的所有控件.

  1. Create a Form called MainForm and place all the controls you're going to be excluded.

1.1将 MainForm BackColor TransparencyKey 属性设置为相同的颜色,例如 Color.Red

1.1 Set both of BackColor and TransparencyKey properties of MainForm to the same color, e.g Color.Red

创建另一个名为 TransparentForm 的表单,并放置所有必须透明的控件.将 ShowInTaskbar 属性设置为 False .

Create another form named TransparentForm and place all controls that must become transparent. Set ShowInTaskbar property to False.

MainForm Load 事件中显示 TransparentForm 并将其发送回.

In the MainForm Load event show the TransparentForm and send it to back.

private void MainForm_Load(object sender, EventArgs e)
{
    TransparentForm form = new TransparentForm();
    form.Opacity = 0.5D;
    form.Show();
    form.SendToBack(); 
}

两种形式的控件的位置都必须使它们组合在一起时显示正确的用户界面.

The position of controls in both form must be such that, when combined, it shows the proper user interface.

这篇关于如何从C#中的WinForm.Opacity中排除控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆