Michael
Michael

Reputation: 13636

How to call a Form from another project

I have two WinForm projects(A,B) in one solution.

A project is VB.Net2

B project is C#.Net4

They both have Form.

The A project is set as startup project and has START button. When I press the button I have to activate Form from the B project.

Any Idea how can Implement it?

Thank you in advance!

Upvotes: 4

Views: 17977

Answers (2)

NetWave
NetWave

Reputation: 399

You first need to get a reference from project A to project B. To do so, right-click project A, select Add Reference, select tab Projects, and double-click project B.

Now you'll be able to reference the form in project B in project A:

Namespace.FormName.Show()

Upvotes: 7

Huske
Huske

Reputation: 9296

  1. In your Project A add a reference to Project B (right-click on the project, Add Reference..., click on Projects tab and add Project B).
  2. In your Project A add Imports ProjectBNamespace
  3. Create a variable of type ProjectBClassName, eg. Dim sample As New SampleForm(), in your button click event handler
  4. Inside this event handler call sample.Show() or sample.ShowDialog(). The first option will open a modeless dialog box, while the other one is a modal dialog box.

Upvotes: 6

Related Questions