C# 我的程序&x27;使用Form.Show()调用预加载程序表单时,s notifyicon会重复
编辑:愚蠢的我。我的预加载程序实际上一直都在显示,即使是使用simpleC# 我的程序&x27;使用Form.Show()调用预加载程序表单时,s notifyicon会重复,c#,winforms,preloader,notifyicon,C#,Winforms,Preloader,Notifyicon,编辑:愚蠢的我。我的预加载程序实际上一直都在显示,即使是使用simpleload.Show()但它就在我的web浏览器下面。我已经在下面发布了一个解决方案。如果你感兴趣的话,请检查一下 我的程序没有窗体,但在通知区域中显示为notifyicon(我的主窗体实际上是隐藏的,用作notifyicon和其他控件的虚拟窗体)。它通过使用URI模式(tkh)从web浏览器调用来运行。若我的程序已经在运行,并且用户从浏览器调用它,它将根据其参数执行操作。例如,如果用户使用tkh:readCard调用它,我的
load.Show()代码>但它就在我的web浏览器下面。我已经在下面发布了一个解决方案。如果你感兴趣的话,请检查一下
我的程序没有窗体,但在通知区域中显示为notifyicon(我的主窗体实际上是隐藏的,用作notifyicon和其他控件的虚拟窗体)。它通过使用URI模式(tkh
)从web浏览器调用来运行。若我的程序已经在运行,并且用户从浏览器调用它,它将根据其参数执行操作。例如,如果用户使用tkh:readCard
调用它,我的程序将在readCard
函数中执行一些操作
下面是我从URI模式中读取参数的代码
public string CommandLine { get; set; }
public bool CheckForProtocolMessage(Uri uri)
{
if (uri.ToString().Length > 1)
{
string[] args = uri.ToString().Split(':');
CommandLine = args[1];
if (args[0].Trim().ToUpper() == "TKH" && args.Length > 1)
{
if (args[1].Length > 1)
{
switch (args[1].Trim().ToUpper())
{
case "READCARD":
if (hasCardReader == true)
{
var bw_readCard = new BackgroundWorker { WorkerReportsProgress = true };
bw_readCard.DoWork += delegate
{
preloaderShow();
readCard();
preloaderClose();
};
bw_readCard.ProgressChanged += delegate { };
bw_readCard.RunWorkerCompleted += delegate { };
bw_readCard.RunWorkerAsync();
bw_readCard.Dispose();
return true;
}
else
{
MessageBox.Show("Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
case "READCARD_IDONLY":
if (hasCardReader == true)
{
var bw_readCard_IDOnly = new BackgroundWorker { WorkerReportsProgress = true };
bw_readCard_IDOnly.DoWork += delegate
{
preloaderShow();
readCard_IDonly();
preloaderClose();
};
bw_readCard_IDOnly.ProgressChanged += delegate { };
bw_readCard_IDOnly.RunWorkerCompleted += delegate { };
bw_readCard_IDOnly.RunWorkerAsync();
bw_readCard_IDOnly.Dispose();
return true;
}
else
{
MessageBox.Show("Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
}
}
return false;
}
预加载()代码>和预关闭()代码>用于显示和关闭预加载窗体。(我的名为“加载”的预加载表单)
这里是preforershow()代码>功能
private void preloaderShow()
{
Loading Loading = new Loading();
Loading.Show();
}
private void preloaderClose()
{
Loading Loading = new Loading();
Application.OpenForms
.OfType<Form>()
.Where(form => String.Equals(form.Name, "Loading"))
.ToList()
.ForEach(form => form.Close());
}
和preforerclose()代码>功能
private void preloaderShow()
{
Loading Loading = new Loading();
Loading.Show();
}
private void preloaderClose()
{
Loading Loading = new Loading();
Application.OpenForms
.OfType<Form>()
.Where(form => String.Equals(form.Name, "Loading"))
.ToList()
.ForEach(form => form.Close());
}
预加载程序将显示,Notify图标将复制如下
我将需要关闭“主”通知图标,使其全部消失
我需要做什么?谢谢。事实上,预加载程序出现了,但它一直在我的web浏览器下方。我所需要做的就是创建以下覆盖函数,使其始终位于顶部(同时使我的Windows不会关注此预加载窗体)
引用此线程:@RonBeyer它在我的任务管理器中有一个实例。我的程序使用IPC来防止多个实例。我的IPC代码参考了本教程: