Por cierto, les mando el ejemplo para un formulario normal (porque el ejemplo de arriba es para MDI)
C#
Cita: private void button1_Click(object sender, System.EventArgs e) {
foreach (Form f in this.OwnedForms) {
if (f is Form2) {
f.Show();
f.Focus();
return;
}
}
Form2 f2 = new Form2();
this.AddOwnedForm(f2);
f2.Owner = this;
f2.Show();
}
y en el formulario 2 no olviden liberarlo...
Cita: private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
Owner.RemoveOwnedForm(this);
}
vb.net Cita: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each f As Form In Me.OwnedForms
If TypeOf f Is Form2 Then
f.Show()
f.Focus()
Exit Sub
End If
Next
Dim f2 As New Form2
Me.AddOwnedForm(f2)
f2.Owner = Me
f2.Show()
End Sub
Formulario 2:
Cita: Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Owner.RemoveOwnedForm(Me)
End Sub
Salu2 y cualquier comentario es bienvenido..