儿童winform的深色透明层 [英] Dark Transparent Layer for child winform

查看:49
本文介绍了儿童winform的深色透明层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In some Webpages like a modal popup, I need one feature in My C# WinForm Application.

While A Child Form is Active the Parent Form in the Background should have transparent dark layer on It, So that User Can easily focus on Active Form.

If Parent form Itself got activated, that dark layer should not appear.

推荐答案

创建一个没有任何边框的整个表单,半透明。确保它没有显示在任务栏中,并且由主窗体拥有。将它放在主表单的顶部,具有相同的大小和位置。然后通过 ShowDialog 激活表单,将此表单作为其所有者。当模态完成时别忘了隐藏它。



一个重要的注意事项:你使用的是父母和孩子这两个词。这是错的。即使表单是控件并具有此类属性,表单的父/子关系也会有效地呈现为不存在。你仍然可以使一个表格成为其他形式的孩子,但这没有任何意义,并会抛出异常。 (你可以通过将表单的 TopLevel 指定为false来解决这个限制,但是不要这样做,它不能做任何好事。)



您真正想要使用的关系是所有者。始终使所有表单由一个表单(通常是主表单)拥有,它将保持应用程序表单在Z顺序中的完整性。此外,为所有拥有的表单设置 ShowInTaskbar false非常重要。可以对一些不常用的设计进行排除。



-SA
Create a whole form without any borders, semi-transparent. Make sure it is not shown in task bar and is owned by the main form. Put it on top of your main form, with same exact size and position. Then activate a form by ShowDialog, having this form its owner. Don't forget to hide it when modal state is complete.

One important note: you are using the terms "parent" and "child". This is wrong. Even though forms are controls and have such properties, the parent/child relationships for forms is effectively rendered defunct. You can still make a form a child of other form, but it makes no sense and will throw an exception. (You can work around this limitation by assigning form's TopLevel to false, but don't do it, it cannot make anything good.)

The relationship you really want to use is Owner. Always make all your forms owned by one form (usually main), it will preserve integrity of the application forms in Z-order. Also, it's important to make ShowInTaskbar false for all owned forms. Exclusion can be made for some unusual designs, rarely used.

—SA


这篇关于儿童winform的深色透明层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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