How to open a form previously created in visual basic from another in Visual C #?

1

I have an initial window called "Main" this window is created in Visual Studio 2015 in C #, and another one called "Secondary" also created in visual Studio 2015 but in VB, both windows are within the same project.

In the "Main" window there is a button, which will open the "Secondary" window and close the "Main" window at the same time, this action is executed under the following instruction: (This instruction is in C # and what you will do is go from the "Main" window to the "Secondary" window)

 private void ButtonIr_Click(object sender, EventArgs e)
    {
        Secundaria s = new Secundaria();
        s.Visible = true;
        this.Dispose(false);
    }    

While in the "Secondary" window there is another button called Back, the function of this button will be to carry from the "Secondary" window to the "Main" window, and close the Secondary window at that same instant in time, the problem is that VB does not recognize the reference of the "Main" window as it did in C # when I entered the code to go to the "Secondary" window from the "Main" window; I tried to use this instruction: (but I did not find it useful to return to the "Main" window even if it works to take you to a new window)

 Private Sub ButtonVolver_Click(sender As Object, e As EventArgs) Handles ButtonVolver.Click
    Dim p As New Principal()
    p.Show()
    Dispose(False)
End Sub

It should be noted that the project in general the first window created was the "Main" window in C # and then the project in VB was added to the "Secondary" window, I do not know if that directly influences the references or if it does not matter for nothing.

If someone knows what I'm doing wrong or what instruction I need to declare in VB so that I recognize the reference of the main window would be very useful, and thanks in advance.

    
asked by E.V001 03.10.2016 в 20:00
source

2 answers

1

I recommend that you use modal forms if you have to have the main form always running. The thing is simple, it would be something like this:

On your Main form you have to do this:

private void ButtonIr_Click(object sender, EventArgs e)
{
    Secundaria s = new Secundaria();
    s.ShowDialog();
}    

And in the secondary simply close it when you want to return:

Private Sub ButtonVolver_Click(sender As Object, e As EventArgs) Handles ButtonVolver.Click
    Me.Close();
End Sub
    
answered by 04.10.2016 в 15:28
-1

I also think I can add a line of code so that when the main main secondary school is left inactive but visible and when secondary closure is reactivated principal, it would be something like this:

private void ButtonIr_Click(object sender, EventArgs e) { Secundaria s = new Secundaria(); s.ShowDialog(); this.Enabled = false; }

and in secondary schools, when they are closed, activate again the main one

    
answered by 04.10.2016 в 16:03