K
Karan
I am calling finalize when form2 loads and deactivates form1 which closes
form1. However, same thing is not happening in form2 because finalize is
already called. Does anybody has solution to it. This code works well for
splash screen. I searched alot on net for codes but they don't work. for
example-
(1)
Public Sub CloseForm(formType As System.Type)
For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren
If oForm.GetType() = formType Then
oForm.Dispose()
oForm.Close()
Next
End Sub
'how to use?
' CloseForm(TypeOf Form3)
(2)
--- code from FormSplash.cs ----
private FormMain formMain;
private ApplicationContext appContext;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//create splash and main forms to be used with the application context
FormSplash formSplash = new FormSplash();
formMain = new FormMain();
// set the main form of the application context object to be the splash
screen. When the splash screen is closing, it will switch the MainForm
property to be the instance of formMain.
appContext.MainForm = formSplash;
// run the application context (this shows the splash screen)
Application.Run(appContext);
}
protected override void OnClosing(CancelEventArgs e)
{
// the splash screen is about to close. Tell the application context to
now wait until the main form is closed before exiting the application. You
could put this code in many places but this seems to be just as easy as
anywhere else I could think of.
appContext.MainForm = formMain;
// hide this screen and show the main screen
this.Hide();
formMain.Show();
base.OnClosing (e);
}
--- end sample code ---
###My Own Code###
Form1 Code
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
Dim frm As New Form2
frm.Show()
End Sub
Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
finalize()
End Sub
Form2 Code
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Application.Exit()
End Sub
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
Dim frm As Form1
frm = New Form1
End Sub
Private Sub Form2_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
finalize()
End Sub
waiting for rerply
Thank you
Karan
form1. However, same thing is not happening in form2 because finalize is
already called. Does anybody has solution to it. This code works well for
splash screen. I searched alot on net for codes but they don't work. for
example-
(1)
Public Sub CloseForm(formType As System.Type)
For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren
If oForm.GetType() = formType Then
oForm.Dispose()
oForm.Close()
Next
End Sub
'how to use?
' CloseForm(TypeOf Form3)
(2)
--- code from FormSplash.cs ----
private FormMain formMain;
private ApplicationContext appContext;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//create splash and main forms to be used with the application context
FormSplash formSplash = new FormSplash();
formMain = new FormMain();
// set the main form of the application context object to be the splash
screen. When the splash screen is closing, it will switch the MainForm
property to be the instance of formMain.
appContext.MainForm = formSplash;
// run the application context (this shows the splash screen)
Application.Run(appContext);
}
protected override void OnClosing(CancelEventArgs e)
{
// the splash screen is about to close. Tell the application context to
now wait until the main form is closed before exiting the application. You
could put this code in many places but this seems to be just as easy as
anywhere else I could think of.
appContext.MainForm = formMain;
// hide this screen and show the main screen
this.Hide();
formMain.Show();
base.OnClosing (e);
}
--- end sample code ---
###My Own Code###
Form1 Code
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
Dim frm As New Form2
frm.Show()
End Sub
Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
finalize()
End Sub
Form2 Code
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Application.Exit()
End Sub
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
Dim frm As Form1
frm = New Form1
End Sub
Private Sub Form2_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
finalize()
End Sub
waiting for rerply
Thank you
Karan