如何隐藏MainForm的,仍然运行的程序? [英] How to hide the mainform and still run the program?

查看:419
本文介绍了如何隐藏MainForm的,仍然运行的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要与图标显示在系统托盘中,但没有MainForm中从一开始就呈现出运行我的程序。

I want to run my program with the icon showing in the system tray but without the mainform showing from the start.

编辑:

  lMainForm := new MainForm; 
  lMainForm.ShowInTaskbar := true;
  Application.Run(lMainForm);

没有工作。只要Application.Run执行,MainForm中随在系统托盘中的图标显示出来。

Didn't work. As soon as Application.Run is executed, mainform is displayed along with the icon in the system tray.

推荐答案

您目前所面对的问题是,你调用的 Application.Run 重载采取的主要形式作为参数。这将显示您不想要的主要形式。

The problem you have at the moment is that you are calling the Application.Run overload that takes the main form as a parameter. This will show the main form which you do not want.

相反,你应该打电话通知其他之一 Application.Run 过载。

Instead you should call one of the other Application.Run overloads.

例如,你可以调用href="http://msdn.microsoft.com/en-us/library/ms157900.aspx" rel="nofollow"> 无参数超负荷 。请确保您已经创建并安装到您的通知图标,你这样做了。而且还可以创建,但不会显示你的主要形式。

For example you can call the no parameter overload of Application.Run. Make sure that you have created and installed your notify icon before you do so. And also create, but do not show your main form.

当你准备好展示你的主要形式,在应对上的通知图标的动作,叫 lMainForm.Show 。您还希望安排在点击窗体上的关闭按钮只是隐藏了形式,而不是将其关闭。我假设你希望你的主要形式,比如坚持隐藏在后台。

When you are ready to show your main form, in response to an action on the notify icon, call lMainForm.Show. You will also wish to arrange that clicking the close button on the form merely hides the form rather than closing it. I'm assuming that you want your main form instance to persist hidden in the background.

所以你的程序的顶层是这样的:

So the top-level of your program would look like this:

//create and show the notify icon here
lMainForm := new MainForm; 
lMainForm.ShowInTaskbar := true;
lMainForm.Visible := false;//I believe this is the default in any case
Application.Run;

您需要将项目添加到该关闭应用程序的通知图标菜单。以实现此:

You'll need to add an item to the notify icon menu that closes the application. Implement this with:

Application.Exit;

如果您需要更细粒度地控制应用程序生命周期,那么你可能会更好使用的,其接收的 Application.Run 超载http://msdn.microsoft.com/en-us/library/system。 windows.forms.applicationcontext.aspx相对=nofollow> 的ApplicationContext

If you need more fine grained control over the application lifetime then you may be better off using the Application.Run overload that receives an ApplicationContext.

由于我没有棱镜的手,我已经检查了这一点,用C#/ WinForms和我希望它转移佯装棱镜!

Since I don't have Prism at hand I have checked this out with C#/WinForms and I hope it transfers alright to Prism!

这篇关于如何隐藏MainForm的,仍然运行的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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