Share via


Open a form from another project in the same solution

Question

Saturday, January 28, 2017 9:56 AM

Hello.

I tried so many things but none of them worked. How would i open a form in VB project that is in the same solution, but in the different project(C#).

I would like to open Form1 that is in File Scan project from Main form that is in Main project with a button.

All replies (3)

Saturday, January 28, 2017 10:45 AM âś…Answered | 2 votes

1. Add a reference to the FileScan project from your Main project. You do this under Project->Add Reference->Projects->Solution in Visual Studio.

2. Create an instance of Form1 and call the Show method of it in a button event handler of the Main form:

    Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
        Dim form As New FileScan.Form1
        form.Show()
    End Sub

Hope that helps.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


Saturday, January 28, 2017 10:14 AM

Hello,

It's a good idea to indicate what you have tried.

No matter which way you go, vb to c or c to vb we must use a using or import statement to reference the other form e.g.

C to VB

var f = new WindowsApplication1.Form1();
f.Show();

VB to C

Dim f As New WindowsFormsApplication1.Form1
f.Show()

There is a caught, if you want to access say a TextBox on the foreign form you will get an error while trying indicating it's not possible because it's declare with protection level so in the property window say for a TextBox we change private to public for C while Friend to Public for VB.

That is the basics, if it does not work then by all means provide specific details to exactly what you want and what you tried.

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator


Saturday, January 28, 2017 1:05 PM

Thank you. It works.