Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
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:
C#
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.
Posted
Comments
Sergey Alexandrovich Kryukov 25-Jan-13 12:02pm    
Other "project"? Even the question makes no sense.

If you mean "other assembly", it could be possible.

Talking about client-server, you need to explain what do you mean, exactly. It might make some sense, only remotely :-)

—SA
dr_iton 26-Jan-13 5:00am    
I meaned how to open forms from different namespaces.
I created a program from twoo namespaces, in second namespace I have 4 forms which ones somehow using .Net and .Net.Sockets need to communicate with one form in first namespace.
P.S. The data of namespace2 forms are stored in three text files inside namespace1.
One more question: If I press debug, the form from namespace one is not Showing. How to fix it.
Thank you in advance for your reply.
Sergey Alexandrovich Kryukov 26-Jan-13 5:22am    
Namespaces means nothing. It's just naming. There is no such thing as "from namespace". You can open anything from any namespace, with no limitation.

Probably, you need to know how to create and reference assemblies. Then, you can use anything from other assemblies in exact same way as the same assembly, but only public declarations.

And namespaces are irrelevant: any assembly may declare any number of namespaces, two different assemblies declare the same assembly...

—SA
Logi Guna 25-Jan-13 12:16pm    
let "Client Side" open form2 by itself, then "Server Side" can give notification to "Client Side" to open form2. if this what you want, it still possible.
dr_iton 25-Jan-13 12:37pm    
That is what I'm trying to do.
Is there a way to make that hapen.
I'm still learning c# programming and I'm courious to know that if its possible or not.
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. I know how to get the data from Server to Clent in Console Application, but I don't know how to do that in Windows Form Application in net framework 3.5.

1 solution

I assume you have Form1 as main form in "Client Side".

Code for Form1 "Client Side"
C#
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)
C#
// 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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900