Ken Kolda
11/3/2004 4:21:00 PM
When your server app starts up, it probably does something like the
following in its Main() routine:
Application.Run(new Form1());
What you can do is create a static field in the Form1 class to hold your
"main" form instance, e.g.
public class Form1 : System.Windows.Form
{
public static Form1 MainForm;
public static Main()
{
MainForm = new Form1();
Application.Run(MainForm);
}
}
Then, in your remoted class's SetVisible() function, just do the following:
public void SetVisible(bool visible)
{
if (Form1.MainForm.InvokeRequired)
Form1.MainForm.Invoke(new someDelegate(SetVisible), new object[] {
true });
else
Form1.MainForm.Visible = visible;
}
Hope that helps -
Ken
"George Kustas" <gkustas@hvc.rr.com> wrote in message
news:b4c52ba8.0411021748.555e69a5@posting.google.com...
> In the "old days", I could make a windows application an ActiveX exe,
> and expose all the properties and methods I wanted. I could allow a
> remote application to show and/or hide the application, or access
> application data(i.e. current customer number in a customer order
> application).
>
> I now have a csharp windows forms app, and I'm trying to acheive the
> same via remoting. I googled my brains out, looked at codeguru, etc.,
> and I still can't find an item or example that does what I'm looking
> for.
>
> Lets say all I want to do is allow a remote client to make my main
> application window visible or not visible...
>
> 1. I create a remotable class called Remote1, by inheriting
> MarshalByRefObject.
> 2. I add a method to Remote1 called SetVisible(bool visible).
> 3. I create a windows form application with a class Form1, and a
> Main().
> 4. In Main(), I know how to register my remotable class Remote1, and I
> know how to instatiate it.
> 5. I also know how to write the client code to access the remotable
> object.
>
> But... How can my remotable class access my application's Form1 class
> to make it visible or not?
>
> An example here (or even an explanation) will help greatly... Thanks