Search code examples
c#.netwinforms

How to run two forms at startup in winforms application?


Let's consider this scenario: a freshly create windows form application in which I created a Form2 besides the original Form1.

1st Question: I want both forms to show up at start-up, so i basically wanted to add Application.Run(new Form2()); in main right after the similar command for Form1, but since I read that I can't use multiple threads to run both forms, how do I do it?

2nd Question: How do I access the form methods from an outside class or even main, since even if I create a form instance I can't seem to access them directly.

3rd Question: I need to display a buffer of messages in a form, typically I would use a simple text box, but the problem is that I need to add something like a mark as read to all individual messages. Any clues on how to do that?


Solution

  • 1: Check out the ApplicationContext class.

    2: The methods need to be public but be careful here because you will start having issues with tight coupling. For a simple implementation, you'll need to pass references to the calling objects (consider researching the Observer pattern).

    3: Check out a DataGridView.