在Windows服务中打开表单 [英] Opening a form in a Windows service
问题描述
您好,
有没有办法让表格成为Windows服务应用程序的一部分
并在双击系统托盘时启动它icon?
我已经有NotifyIcon工作,并为它添加了一个事件
_DoubleClick。
我添加了一个表单并试图用以下方式打开它:
{表格名称} .ActiveForm.Show();
我不是确定这是否正确...我在VB世界中长大并且
类似于我习惯用于打开表单的代码。
>
帮助?
谢谢!
Andrew
Hello,
Is there any way to make a form part of a windows service application
and launch it upon double-click of a system tray icon?
I already have the NotifyIcon working and have added an event to it for
the _DoubleClick.
I added a form and tried to open it with:
{Form Name}.ActiveForm.Show();
I am not sure if that is correct or not... I grew up in the VB world and
that is similar to what I am used to using for code to open a form.
Help?
Thanks!
Andrew
推荐答案
显示表单的正确代码是
MyForm f = new MyForm();
f.Show();
但是,我不确定从Windows
服务启动时这是如何工作的,因为该服务可能以不同的用户身份运行,然后
当前logg用户编辑。
" Andrew Mueller" <上午****** @ instechnet.com>在消息中写道
news:uk ************** @ TK2MSFTNGP11.phx.gbl ...
the correct code for showing the form is
MyForm f = new MyForm();
f.Show();
However, I am unsure how this will work when launching from a Windows
service, as the service is likely to be running as a different user then the
currently logged in user.
"Andrew Mueller" <am******@instechnet.com> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
你好,>
有没有办法让窗体服务应用程序的表单成为
并在双击系统托盘图标时启动它?
我已经有NotifyIcon工作了并为_DoubleClick添加了一个事件
。
我添加了一个表单并试图用以下内容打开它:
{Form Name} .ActiveForm.Show ();
我不确定这是否正确...我在VB世界中长大并且类似于我习惯使用的代码打开表格。
帮助?
谢谢!
Andrew
Hello,
Is there any way to make a form part of a windows service application
and launch it upon double-click of a system tray icon?
I already have the NotifyIcon working and have added an event to it for the _DoubleClick.
I added a form and tried to open it with:
{Form Name}.ActiveForm.Show();
I am not sure if that is correct or not... I grew up in the VB world and
that is similar to what I am used to using for code to open a form.
Help?
Thanks!
Andrew
看起来像NotifyIcon的代码没有执行..这就是我
所拥有的:
命名空间EPA
{
公共类EPAClass:System.ServiceProcess.ServiceBase
{
Log log = new Log(); //这是一个日志编写器。它将写入
来提交我发送的任何信息
private System.Windows.Forms.NotifyIcon notifyIcon1;
public EPAClass ()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.notifyIcon1 = new
System.Windows.Forms.NotifyIcon(this.components);
this.notifyIcon1.Text =" EPA Service";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Icon = new System.Drawing.Icon(GetType (),
" Svc.ico");
this.notifyIcon1.Click + = new
System.Windows.Forms.MouseEventHandler (this.notify Icon1_Click);
}
private void notifyIcon1_Click(object sender,
System.Windows.Forms.MouseEventArgs e)
{
log.WriteToLog(通知图标点击);
}
}
}
我没有得到日志文件w ritten ....不知道为什么。这里显然有更多的代码,但这应该足以理解我的问题了。
谢谢!
Andrew Mueller
" Bob Boran" < MC ******* @ hotmail.com>在消息中写道
news:e
It looks like the code for the NotifyIcon is not executing.. Here is what I
have:
namespace EPA
{
public class EPAClass : System.ServiceProcess.ServiceBase
{
Log log = new Log(); //This is a log writer. It will write
to file any information I send it
private System.Windows.Forms.NotifyIcon notifyIcon1;
public EPAClass()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.notifyIcon1 = new
System.Windows.Forms.NotifyIcon(this.components);
this.notifyIcon1.Text = "EPA Service";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Icon = new System.Drawing.Icon(GetType(),
"Svc.ico");
this.notifyIcon1.Click += new
System.Windows.Forms.MouseEventHandler(this.notify Icon1_Click);
}
private void notifyIcon1_Click(object sender,
System.Windows.Forms.MouseEventArgs e)
{
log.WriteToLog("Notify Icon Clicked");
}
}
}
I am not getting the log file written.... Not sure why. There is obviously
more code here, but this should be enough to understand my problem.
Thanks!
Andrew Mueller
"Bob Boran" <mc*******@hotmail.com> wrote in message
news:e
**************** @ tk2msftngp13.phx.gbl ...
****************@tk2msftngp13.phx.gbl...
显示表单的正确代码是
MyForm f = new MyForm();
f.Show();
但是,我不确定从Windows
服务启动时这是如何工作的,因为该服务很可能以不同的用户身份运行,然后是当前登录用户的
。
>安德鲁·穆勒 <上午****** @ instechnet.com>在消息中写道
新闻:英国************** @ TK2MSFTNGP11.phx.gbl ...
the correct code for showing the form is
MyForm f = new MyForm();
f.Show();
However, I am unsure how this will work when launching from a Windows
service, as the service is likely to be running as a different user then the currently logged in user.
"Andrew Mueller" <am******@instechnet.com> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
你好,
>有没有办法让窗体服务
应用程序的表单部分,并在双击系统托盘图标时启动它?
我已经有NotifyIcon工作并添加了事件
Hello,
Is there any way to make a form part of a windows service application and launch it upon double-click of a system tray icon?
I already have the NotifyIcon working and have added an event to it
for
for
_DoubleClick。
我添加了一个表单并尝试用以下方式打开它:
{Form Name} .ActiveForm.Show();
我不确定这是不是正确...我在VB世界中长大并且
类似于我我习惯用代码打开表格。
帮助?
谢谢!
Andrew
the _DoubleClick.
I added a form and tried to open it with:
{Form Name}.ActiveForm.Show();
I am not sure if that is correct or not... I grew up in the VB world and
that is similar to what I am used to using for code to open a form.
Help?
Thanks!
Andrew
这篇关于在Windows服务中打开表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!