如何在应用程序打开两次时创建单个实例应用程序的mdi子项? [英] how to create mdi child of a single instance application when the application is opened twice?
问题描述
请我是C#的新手,我需要你的帮助。
我创建了一个单实例csharp应用程序,它使用我找到的必要代码使用mdi表单网站上最特别的是 http://www.codeproject.com [ ^ ]。
我的问题是当用户尝试打开/运行应用程序两次或更多时,如何创建新的mdi选项卡或子项?因此,不要像在 C#中的单实例应用程序中那样显示或设置焦点已打开的应用程序/ a> [ ^ ],我想创建一个新的mdi标签或子。非常欢迎任何帮助。
单实例功能是从这里获得的 C#中的单实例应用程序 [ ^ ]
非常感谢
Please I am new in C# and i need your help.
I have created a single instance csharp application that uses mdi forms using the necessary code that i find on the web most especially here at http://www.codeproject.com[^] .
My question is how do I create a new mdi tab or child when a user attempt to open/run the application twice or more? So instead of showing or setting focus to already the opened application as in Single Instance Application in C#[^], I would like to create a new mdi tab or child from. Please any help is greatly welcomed.
The single instance functionality was obtained from here Single Instance Application in C#[^]
Thank you very much
推荐答案
if (!OnlyOneProcess())
{
[] send = Encoding.UTF8.GetBytes("ExecuteLink=Something");
SendUDP(IPAddress.Loopback, MY_PORT, send, false);
}
public static bool SendUDP(IPAddress ip, ushort port, byte[] send, bool is_broadcast)
{
try
{
IPEndPoint groupEP = new IPEndPoint(ip, port);
UdpClient udp = new UdpClient();
udp.EnableBroadcast = is_broadcast;
udp.DontFragment = true;
udp.Send(send, send.Length, groupEP);
udp.Close();
return true;
}
catch { }
return false;
}
然后在套接字中捕获消息
And capture the message in socket like that
tudp = LIB.UDPRead(IPUB.PORT, search_udp);
static void search_udp(Socket sender, EndPoint ep, byte[] data, int recv)
{
string stringData = Encoding.UTF8.GetString(data, 0, recv );
}
public static Thread UDPRead(ushort port, dOnUDPRead search)
{
Socket udp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, port);
udp.Bind(iep);
Thread h_b = new Thread(new ParameterizedThreadStart(TUDPRead));
h_b.SetApartmentState(ApartmentState.MTA);
h_b.Name = "BROADCAST";
h_b.Priority = ThreadPriority.BelowNormal;
h_b.IsBackground = true;
h_b.Start(new object[] { udp, iep, search });
return h_b;
}
public delegate void dOnUDPRead(Socket sender, EndPoint e, byte[] data, int count);
static void TUDPRead(object o)
{
object[] ar = (object[])o;
Socket udp = (Socket)ar[0];
IPEndPoint iep = (IPEndPoint)ar[1];
dOnUDPRead ev = (dOnUDPRead)ar[2];
try
{
byte[] data = new byte[20480];
while (true)
{
EndPoint ep = (EndPoint)iep;
int recv = udp.ReceiveFrom(data, ref ep);
if (recv <= 0) continue;
ev(udp, ep, data, recv);
Thread.Sleep(1);
}
}
catch (Exception ex) { LIB.Error(ex, LIB.EError.OnlyLog); }
finally { if (udp != null) udp.Close(); }
}
这篇关于如何在应用程序打开两次时创建单个实例应用程序的mdi子项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!