开发者

C# Winforms Application To Open a Second Winforms Application

开发者 https://www.devze.com 2023-02-03 04:58 出处:网络
I have an small application that I have written that needs to be used/incorporated into about 6 larger pieces.Ideally I want to be able to open this smaller piece from each stand-alo开发者_运维问答ne

I have an small application that I have written that needs to be used/incorporated into about 6 larger pieces. Ideally I want to be able to open this smaller piece from each stand-alo开发者_运维问答ne application instead of adding the code to each one. This would allow for easier maintenance in the event there are changes they only need to take place in one application.

I have looked but I can't seem to figure out how I can open a second winform application from inside of one. Any help would be great.

Thanks


2 options.

1) If this small app can stand alone, meaning it can execute in some useful fashion without being spawned by a parent app, then use Process.Start(). Your application(s) that spawn this process may not be able to run in a partial-trust environment.

Process.Start("notepad.exe");

2) If the app is only useful within the context of the parent apps, say by being given objects or other arguments from the other apps, consider refactoring the small app to allow the form's project to be referenced by the parent apps. Then, your parent apps can simply create a new instance of the form and display it:

var childForm = new SmallAppForm();
childForm.Owner = this; //the child window will close when its owner does.
childForm.Show();

Though it's more code, it's generally easier and more foolproof to implement. The form can also be accessed and thus controlled from elsewhere in the app, and other functionality can be implemented without having to deal with the rather messy business of cross-process communication.


I'd look to make this a Library that's a separate project that you add a reference to from your other projects. Much cleaner than spawning child processes.

0

精彩评论

暂无评论...
验证码 换一张
取 消