从其他项目打开表单时需要帮助。 [英] Help needed in opening a form from other project.
问题描述
我使用带有两个项目的.NET和.NET.Sockets以服务器 - 客户端方式创建了一个程序。
在一个服务器项目中,我有一个表单,它有一个按钮,我想要的只是单击该按钮并在客户端项目中打开一个表单。
如果我只有一个项目,它是这样的:
private void buttonOpenForm_Click( object sender,EventArgs e)
{
Form2 frmForm2 = new Form2();
frmForm2.Show()
}
我有办法打开一个Form2(客户端)表单Form1(服务器端)。
提前感谢您的回复。
我假设您在客户端中将Form1作为主窗体。
Form1客户端的代码
private void Form1_Load( object sender,EventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem( new System.Threading.WaitCallback(此跨度> .ShowForm2));
}
private void ShowForm2( object state)
{
var hWait = new System.Threading.EventWaitHandle( false ,System.Threading.EventResetMode.ManualReset, Global\\Form2Show跨度>);
while ( true ){
hWait.WaitOne(); // 来自ServerSide的等待信号
Form2 f = new Form2();
this .Invoke( new System.Threading.ThreadStart(f.Show));
hWait.Reset();
}
}
服务器端代码(按下按钮时)
// 通知客户端
private void buttonOpenForm_Click( object sender,EventArgs e)
{
System.Threading.EventWaitHandle.OpenExisting( Global \\Form2Show跨度>)设置()。
}
编辑:根据OP回复这个项目的其他问题是,我用文本文件存储数据,我必须将它们存储在programm的服务器端。程序的客户端需要使用套接字来填充表单。
看看此处。
I created a program in a Server - Client manner using .NET and .NET.Sockets with twoo projects.
In a Server project I have a Form which has a button and all I want is to Click in that button and open a form in Client project.
If I have only one project it goes like this:
private void buttonOpenForm_Click(object sender, EventArgs e)
{
Form2 frmForm2 = new Form2();
frmForm2.Show()
}
Is there a way that I can open a Form2 (Client side) form Form1 (Server side).
Thank you in advance form your reply.
I assume you have Form1 as main form in "Client Side".
Code for Form1 "Client Side"
private void Form1_Load(object sender, EventArgs e) { System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.ShowForm2)); } private void ShowForm2(object state) { var hWait = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, "Global\\Form2Show"); while (true){ hWait.WaitOne(); // Waiting signal from ServerSide Form2 f = new Form2(); this.Invoke(new System.Threading.ThreadStart(f.Show)); hWait.Reset(); } }
Code for "Server Side" (when button pressed)
// Notify Client Side private void buttonOpenForm_Click(object sender, EventArgs e) { System.Threading.EventWaitHandle.OpenExisting("Global\\Form2Show").Set(); }
EDIT: according to OP reply "Other question in this project is, I used text files to store the data, I have to store them in Server side of programm. Client side of programm it needs those data to fill the form using Sockets."
Have a look here.
这篇关于从其他项目打开表单时需要帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!