c# Form.Hide() 与 Form.Opacity = 0

发布于 2024-11-10 09:54:20 字数 247 浏览 3 评论 0原文

我想知道使表单完全透明(而不是隐藏它)是否有任何陷阱。例如,我知道隐藏表单时这些事情会让我感到惊讶:

  1. 如果隐藏表单,则无法与其控件交互(无法将 HTML 添加到网络浏览器控件,无法按下按钮等.)
  2. 在窗口隐藏时更改其 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:

  1. 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.)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所谓喜欢 2024-11-17 09:54:20

如果您不再需要该表单,请将其隐藏。
但是,如果您仍然有一个任务或计时器以您想要保留的形式运行,或者您想要保留用户的输入,那么您最好将不透明度设置为 0%。
当我想要隐藏表单但仍处于活动状态时,我会这样做:

frmMain.Opacity = 0; // To make it invisible.
frmMain.VisibleInTaskbar = false; // To make the taskbar entry of the form disappear, and to make sure that the WindowState isn't changed.
frmMain.Enabled = false; // To make sure the user doesn't type something in the form, or presses a button (by pressing enter) by accident.

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:

frmMain.Opacity = 0; // To make it invisible.
frmMain.VisibleInTaskbar = false; // To make the taskbar entry of the form disappear, and to make sure that the WindowState isn't changed.
frmMain.Enabled = false; // To make sure the user doesn't type something in the form, or presses a button (by pressing enter) by accident.
前事休说 2024-11-17 09:54:20

从我的评论的投票来看,我想我会将其作为答案提交。我不鼓励使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文