如何最大限度地减少从任务栏的形式? [英] How to minimize form from taskbar?

查看:191
本文介绍了如何最大限度地减少从任务栏的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的WinForm应用程序,我已经设置formborderstyle =无。 Thatz为什么当我运行应用程序,我无法通过任务栏最小化。是否有任何身体知道该解决方案?

I have developed winform application and I have set formborderstyle=none. Thatz why when I am running application I can't minimize it through taskbar. Does any body knows solution for this?

我试过下面的代码..在我的形式添加。

I tried following code.. adding it in my form.

    const int WS_CLIPCHILDREN = 0x2000000;
    const int WS_MINIMIZEBOX = 0x20000;
    const int WS_MAXIMIZEBOX = 0x10000;
    const int WS_SYSMENU = 0x80000;
    const int CS_DBLCLKS = 0x8;
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.Style = WS_CLIPCHILDREN | WS_MINIMIZEBOX | WS_SYSMENU;
            cp.ClassStyle = CS_DBLCLKS;
            return cp;
        }
    }



我现在能够最大限度地减少从任务栏中的应用程序。但问题是,它是创造我的应用程序其中之一,我需要和另一类则是不必要​​的两个intances。

I am now able to minimize the application from taskbar. But the problem is it is creating two intances of my application one which I need and the other which is unneccessary.

是否有任何身体知道该解决方案..或者有没有人其中有一些作品其他的解决办法?

Does any body knows solution for this.. or does anyone has some other solution which works ?

推荐答案

一个无国界的形式应该永远是一个用户预计不会减少。该发现性原则开始适用于此:大多数用户不知道,你可以通过单击任务栏图标最小化窗口。他们将期望能够通过点击 来做到这一点 - 旁边的大红色 按钮的 X 。在右键的解决办法是选择适合自己的形式,一个包括标题栏和减少箱不同的边框样式。如预期Windows将自动行为。当您按照您的平台的标准约定,不仅对你作为一个程序员,但你的用户事情要容易得多。结果
它还修正了当创建或恢复您的形式讨厌的闪烁效果,我可以看到几秒钟的标准标题栏。

A borderless form should always be one that the user is not expected to minimize. The discoverability principle starts to apply here: most users don't know that you can minimize a window by clicking on its taskbar icon. They're going to expect to be able to do it by clicking the button next to the big red x. The right solution is to choose a different border style for your form, one that includes the title bar and the minimize box. Windows will automatically behave as expected. Things are much easier when you follow the standard conventions of your platform, not only for you as a programmer, but for your users.
It also fixes that nasty flickering effect when your form is created or restored where I can see the standard caption bar for a few seconds.

当然,你不可避免地要做到这一点,无论如何,所以尽管我的判断,我会尽力提供解决方案。第一个问题是的我无法重现您所描述(在Windows Server 2008 R2,.NET 4.0)的行为。究竟增加显示出一个新的WinForms项目中的代码,并设置窗体的 FormBorderStyle 属性设置为无,有没有办法,我可以得到两个窗口露面。点击任务栏图标导致窗体为最小化,单击它再次恢复它。

Of course, you'll inevitably want to do this anyway, so despite my better judgement, I'll try to provide a solution. The first problem is I can't reproduce the behavior you describe (Windows Server 2008 R2, .NET 4.0). Adding exactly the code shown to a new WinForms project, and setting the form's FormBorderStyle property to "None", there's no way I can get two windows to show up. Clicking on the taskbar icon causes the form to minimize, clicking it again restores it.

但有一种方式来简化你的代码。你也许应该的OR-ing,你与现有的样式标志加入,而不是替换现有的标志风格的标志。这种替换您的代码:

But there is a way to simplify your code. And you should probably be OR-ing the style flags that you're adding with the existing style flags, rather than replacing the existing flags. Replace your code with this:

const int WS_MINIMIZEBOX = 0x20000;
const int CS_DBLCLKS = 0x8;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.Style |= WS_MINIMIZEBOX;
        cp.ClassStyle |= CS_DBLCLKS;
        return cp;
    }
}

如果不解决您的问题(我M怀疑,它会),那么我怀疑,还有别​​的东西错在你的代码,你还没有告诉我们。仅仅因为你可以注释掉的几行代码,你的程序工作并不如预期的不一定的暗示,问题就出在这些代码行。它们可以是完全正确的,但你在别处使用的黑客干扰。

If that doesn't fix your problem (and I'm skeptical that it will), then as I suspected, there's something else wrong in your code that you haven't shown us. Just because you can comment out a few lines of code and your program works as expected doesn't necessarily imply that the problem lies in those lines of code. They can be perfectly correct, but interfering with a hack you've used elsewhere.

这篇关于如何最大限度地减少从任务栏的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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