c# Form.Hide() 与 Form.Opacity = 0
我想知道使表单完全透明(而不是隐藏它)是否有任何陷阱。例如,我知道隐藏表单时这些事情会让我感到惊讶:
- 如果隐藏表单,则无法与其控件交互(无法将 HTML 添加到网络浏览器控件,无法按下按钮等.)
- 在窗口隐藏时更改其 WindowState(最小化、最大化等)将导致当窗体再次显示时该窗口出现在工作区域范围之外。
在使用不透明度设置为 0(完全透明)的表单时,是否有人遇到类似的问题(或完全不同的问题!)?
I was wondering if there are any gotchas for making a form completely transparent (as opposed to hiding it). For instance, I know that these are things that got my by surprise when hiding a form:
- If a form is hidden, you cannot interact with its controls (can't add HTML to a webbrowser control, can't push a button, etc.)
- Changing the WindowState (minimized, maximized, etc) of a window while it is hidden will cause the window to appear outside the scope of your work area when the form is shown again.
Has anybody run into similar problems (or completely different ones!) while using a form with opacity set to 0 (completely transparent)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不再需要该表单,请将其隐藏。
但是,如果您仍然有一个任务或计时器以您想要保留的形式运行,或者您想要保留用户的输入,那么您最好将不透明度设置为 0%。
当我想要隐藏表单但仍处于活动状态时,我会这样做:
If you don't need the form anymore, hide it.
But if you still have a task or timers running in the form you want to keep, or you want to keep the user's input, then you'd do good to set the opacity to 0%.
This is what I do when I want a form to be hidden, but still active:
从我的评论的投票来看,我想我会将其作为答案提交。我不鼓励使用
Form.Opacity = 0
。尽管您可以禁用该表单以防止意外交互,但我认为透明表单会覆盖其他窗口,并使用户感到困惑,为什么他无法与透明表单后面的窗口进行交互。至于
Form.Hide()
的问题,我通常会对表单响应进行排队,以便当表单返回视图(或可见性)时,它会通过队列来处理操作(即更改 FormState)。在隐藏时更改表单也会让用户感到困惑。From the up votes for my comment, I guess I'll submit it as an answer. I would discourage using
Form.Opacity = 0
. Even though you can disable the form to prevent accidental interaction, I would think the transparent form would overlay other windows and confuse the user as to why he can't interact with windows behind your transparent one.As for the gotcha's for
Form.Hide()
, I typically queue form responses so that when the form returns into view (or visibility), it goes through the queue to process actions (i.e. changing FormState). Changing the form while it's hidden can also really confuse the user.