1
votes

My Monomac project has 2 forms (Form/Views): Mainwindow and form2. (I created form2 using: New -> monomac -> Cocoa View with controller > name is : form2)

On the MainWindow form I have a button. I want to make form2 show/visible when I click that button.

Action when button is clicked is: a1. This is my code :

partial void a1 (NSObject sender) 
{ 
    Console.WriteLine ("a1 call form2");
    var f1 = new form2Controller();
    f1.LoadView();

} 

I want to show form2 once the view is loaded, what must I do?

2

2 Answers

0
votes

If you've created a "Cocoa Window with controller", then you want to do this to show the window:

f1.Window.MakeKeyAndOrderFront();

If you've created a "Cocoa View with controller", then you have to hook up your window that you added to the xib to an outlet, then call it like:

f1.MyOutletForTheWindow.MakeKeyAndOrderFront();
0
votes

To make a window visible, you will need to call the ShowWindow method of the view controller.

partial void a1 (NSObject sender)
{
    Console.WriteLine ("a1 call form2");
    Form2Controller form = new Form2Controller();
    form.ShowWindow(this);
}