notifyIcon上的C#事件绑定无法写入
我正在为我的公司开发一个桌面应用程序,似乎无法使此代码在notifyIcon.MouseClickEvent上的MouseClickEvent绑定范围内工作。下面是代码,全面了解应该做什么会很有帮助。我确实有一个程序:ApplicationContext,并将其更改为Program:Form。这是一个愚蠢的新手错误,但我只是不太会做C#编程,而且已经和代码斗争/阅读了大约两天了,似乎无法解决这个问题。请帮我少吸点。:-)notifyIcon上的C#事件绑定无法写入,c#,C#,我正在为我的公司开发一个桌面应用程序,似乎无法使此代码在notifyIcon.MouseClickEvent上的MouseClickEvent绑定范围内工作。下面是代码,全面了解应该做什么会很有帮助。我确实有一个程序:ApplicationContext,并将其更改为Program:Form。这是一个愚蠢的新手错误,但我只是不太会做C#编程,而且已经和代码斗争/阅读了大约两天了,似乎无法解决这个问题。请帮我少吸点。:-) 通知图标的事件由消息泵(Application.Run())处理,但您没有
通知图标的事件由消息泵(
Application.Run()
)处理,但您没有消息泵。由于命名管道调用将阻止调用,我建议您在单独的线程中调用ListenForSignal
。请注意,如果执行此操作,则需要使用invokererequired
和Invoke
更新GUI。通知图标的事件由消息泵(Application.Run()
)处理,但您没有消息泵。由于命名管道调用将阻止调用,我建议您在单独的线程中调用ListenForSignal
。请注意,如果执行此操作,则需要使用invokererequired
和Invoke
来更新GUI。因此,问题在于单击托盘图标时消息框不会出现?是的,这就是问题所在。很抱歉没有弄清楚。所以问题是当您单击托盘图标时,消息框没有出现?是的,这就是问题所在。很抱歉没有弄清楚。聪明的一点是,将后端侦听器放在一个单独的线程上是明智的。。。我应该想到那个。然而,在底部我有Application.Run(pg);不确定你是否错过了它,或者我是否定义得很糟糕。将ListenForSignal移动到它自己的线程修复了所有问题。我应该与我的内部Erlang开发人员联系并注意到这一点。明智的做法是,将后端侦听器放在单独的线程上。。。我应该想到那个。然而,在底部我有Application.Run(pg);不确定你是否错过了它,或者我是否定义得很糟糕。将ListenForSignal移动到它自己的线程修复了所有问题。我应该与我的内部Erlang开发人员联系并注意到这一点。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.IO.Pipes;
using System.Security.Principal;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
namespace ShipItClient
{
public class Program : Form
{
private NotifyIcon notifyIcon;
private Program()
{
SetupTray();
ListenForSignal();
}
protected void notifyIcon_Click(object Sender, MouseEventArgs e)
{
MessageBox.Show("Double Click");
CustomQuoteForm quoteForm = new CustomQuoteForm();
quoteForm.Show();
}
private void SetupTray()
{
// Create the NotifyIcon.
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.MouseClick += new MouseEventHandler(notifyIcon_Click);
notifyIcon.Icon = ShipItClient.Properties.Resources.ShipIt4Sage;
notifyIcon.Text = "ShipIt - Shipping Rate Quotes on Demand";
notifyIcon.Visible = true;
}
private void ListenForSignal()
{
String username = WindowsIdentity.GetCurrent().Name;
String pipeName = "shipit_" + username.Split('\\')[1];
NamedPipeClientStream pipeClient =
new NamedPipeClientStream(".", pipeName,
PipeDirection.InOut, PipeOptions.None);
pipeClient.Connect();
while (pipeClient.IsConnected)
{
if (pipeClient.ReadByte() == 1)
{
string[] shipit_files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "XML_*.xml");
foreach (String file in shipit_files)
{
string xml = File.ReadAllText(file);
XmlSerializer serializer = new XmlSerializer(typeof(ShipIt));
ShipIt ship_it = (ShipIt)serializer.Deserialize(new StringReader(xml));
//Get ShipIt Quote Window
RateGrid rateGrid = new RateGrid();
//rateGrid.Visibility = System.Windows.Visibility.Visible;
File.Delete(file);
}
}
}
}
private void GetCarrierRates(ShipIt ship_it)
{
FedExRates fedexRates = new FedExRates(ShipItClient.Properties.Settings.Default.FedEx_Account_Number, ShipItClient.Properties.Settings.Default.FedEx_Meter_Number, ShipItClient.Properties.Settings.Default.FedEx_Service_Key, ShipItClient.Properties.Settings.Default.FedEx_Service_Password);
ArrayList rates = fedexRates.GetRate(ship_it);
}
[STAThread]
public static void Main()
{
Program pg = new Program();
Application.Run(pg);
}
}
}