当其任务栏图标隐藏C#时如何聚焦模态窗体 [英] How to focus a modal form when its taskbar icon hidden C#

查看:103
本文介绍了当其任务栏图标隐藏C#时如何聚焦模态窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我只想关注一个顶级形式的表格。



我使用Form聚焦第二个表单。 Showdialog()。

现在我的问题是隐藏了第二个表单的任务栏图标。



所以只有父表单的任务栏图标可见。



如果我点击第一个表格的任务栏图标,只有第一个表格可见而第二个表格是隐藏的。



注意:我无法聚焦第二种形式,即顶层形式。如何点击第一个表单任务栏图标点击它。





如何摆脱这个问题。


I just want to focus a form which was the toplevel form.

I focused the Second form using Form.Showdialog().
Now my problem is that Second form's taskbar icon is hidden.

So Only the parent form's taskbar icon is visible.

If I click on the taskbar icon of the first form only first form is visible whereas second form is hidden.

Note: I can't focus the second form which is the toplevel form. How to fous it when first forms taskbar icon clicked.


How to get rid of this problem.

推荐答案

首先,问题与代表您表单的任务栏图标的可见性无关,但我知道您在询问,因为您无需点击任何内容。你可以通过编程方式完成,但为什么呢?



这是一个复杂的问题,所以我只列出一些你需要关心的事情;并且你试着自己把它放在一起,因为你的问题没有明确解释:

  • 表格不是聚焦但是被激活

    https: //msdn.microsoft.com/en-us/library/system.windows.yforms.form.activate%28v=vs.80%29.aspx [ ^ ]。
  • 除非切换到另一个应用程序,否则不应该松开模态的表单的活动状态。没有理由强制激活您的申请表格;用户知道的更好。如果用户切换到另一个应用程序,则认为它是故意完成的。
  • 在切换到其他应用程序方面,您应该更好地维护所有应用程序表单的Z顺序。你形成的Al应该以桌面的Z顺序聚集在一起。如果您在所有表单之间维护所有者拥有的关系,则可以轻松实现它: https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner%28v=vs.80%29.aspx [<一个href =https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner%28v=vs.80%29.aspx\"target =_ blanktitle =New Window > ^ ](另见其他相关成员,但这个就足够了。)



    实际上,只需要一个主表格就足够了所有其他表单的所有者并保持主表单始终可见(我并不是说它不能被其他形式的应用程序或其他应用程序覆盖,它可以)。然后,无论Z-order中的顶部是什么形式,当您激活任何形式的应用程序时,它将以某种顺序将所有其他表单移到顶部,因此其他应用程序的窗口都不会潜入其中。
  • 将以前的技术与使用 Form.ShowInTaskbar 结合起来是很好的:

    https://msdn.microsoft.com/en-us/library/ system.windows.forms.form.showintaskbar%28v = vs.80%29.aspx [ ^ ]。



    与上面匹配的基本设计是这样的:对于主表单,使该属性为true,对于所有其他表单,为false;这样,如果用户使用任务栏激活您的应用程序(任务栏将始终只显示您的应用程序的一个项目,唯一一个点击),如果应用程序显示模式表单,您的某些表单将被激活此时,顶级模态表单将被激活。这应该可以解决你的问题。



    同时,你可以偏离这种风格,故意添加 Form.ShowInTaskbar 对于其他一些选择形式是真的,例如你的模态形式。我不喜欢这种风格,因为它会让用户选择点击什么,只需点击一下就没有意义。您还可以维护以下规则:一次只有一个表单应该具有此属性等于true。但我不打扰;最简单的规则只显示任务栏中的主窗体就足够了。
  • 更好的是,更喜欢只有一个主窗体的设计。什么是其他形式,可以成为主要形式的一些控件,它可以是面板(显示和隐藏,可选地调整大小), TabPage 实例 TabControl ,依此类推。我不是指一些更多的形式;你可以拥有少量的,也不要过头。这种设计最容易导航和理解。您甚至可以使用动态对接开发类似于Visual Studio的UI。
  • 同时,永远不要使用MDI。请不要。
First of all, the problem has nothing to do with the visibility of the taskbar icon representing your form, but I understand that you are asking because you have nothing to click on. You can do it programmatically, but why?

It's a complex of problems, so I just list some things you need to care for; and you try to put it together yourself, because your problem is not clearly explained:
  • Forms are not "focused" but are activated:
    https://msdn.microsoft.com/en-us/library/system.windows.yforms.form.activate%28v=vs.80%29.aspx[^].
  • You shouldn't loose the active state of a form in a modal state, unless you switch to another application. There is no a reason to force activation of your application's form; the user knows better. If the user switches to another application, assume it's done on purpose.
  • You should better maintain the Z-order of all application forms in respect to the switching to other applications. Al you forms should come together in Z-order of the desktop. You can easily achieve it if you maintain owner-owned relationship between all forms: https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner%28v=vs.80%29.aspx[^] (see also other related members, but this one would be enough).

    Practically, it would be enough to make a main form an owner of all other forms and keep the main form always visible (I don't mean it cannot be covered by other forms of your application or other applications, it can). Then, no matter of what form is on top in Z-order, when you activate any form of your application, it will move all other forms on top in some order, so none of the windows of other applications will sneak in between.
  • It's good to couple the previous technique with the use of Form.ShowInTaskbar:
    https://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar%28v=vs.80%29.aspx[^].

    The base design matching the above would be this: make this property true for your main form, false for all other forms; this way, if the user activates your application using the taskbar or not (taskbar will always show only one item per your application, the only one to click on), some of your forms will be activated, if the application is showing a modal form at this moment, the top-level modal form will be activated. That should solve your problem.

    At the same time, you can deviate from this style, intentionally adding Form.ShowInTaskbar true for some other select form, such as your modal form. I don't like this style, because it will give the user a choice what to click on, and one click would make no sense. You could also maintain the following rule: only one form at a time should have this property equal to true. But I would not bother; the simplest rule showing only the main form in the taskbar is good enough.
  • Even better, prefer the design with only one main form. What was other forms, could become some controls withing the main form, it can be panels (showing and hiding, optionally resizing), TabPage instances in an instance of TabControl, and so on. I don't mean some more modal form; you can have some small number of them, also don't overdo it. Such design is the easiest to navigate and understand. You can even develop the UI similar to Visual Studio, with dynamic docking.
  • At the same time, never use MDI. Just don't.


这篇关于当其任务栏图标隐藏C#时如何聚焦模态窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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