|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
close Form1 & open Form2form1. 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 "Karan" <karan***@hotmail.com> schrieb You must never call Finalize. This is done by the GC immediatelly before > I am calling finalize when form2 loads and deactivates form1 which destroying the object. To close a Form, call it's close method only. If you don't need the Form instance anymore, remove the reference. Later, whenever the GC does it's work, the Form object is destroyed. Show quoteHide quote > closes form1. However, same thing is not happening in form2 because Public Sub CloseForm(formType As System.Type)> 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) For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren If oForm.GetType() Is formType Then '<----- "=" replaced by "Is" oForm.Close() Next End Sub Calling oForm.Dispose() is not necessary because it is called anyway whenever the Form is closed. 'how to use? ' CloseForm(TypeOf Form3) CloseForm(GetType(Form3)) Show quoteHide quote > (2) I do not completely understand what's your intention:> > --- 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 The code in Form1.btnShow_Click looks ok. Delete subs Form1_Deactivate and Form2_Deactivate. In Form2.btnShow_Click, there seems to be a "frm.Show" missing. Looking at btnShow_Click: Do you want to close Form1 if you open Form2, and close Form2 if you open Form1? Then you should add Me.Close in btnShow_Click after showing the other Form. If there is no Form that will live from the start till the end of the application, use this Sub Main: Sub Main 'In a Module. In a Class, use Shared Sub Main Dim f as Form1 f.Show application.run() end sub Armin Hi Armin
f.show() is giving me error nullreferance > Sub Main 'In a Module. In a Class, use Shared Sub Main There is a button on form1 show, on click of that button form1 should close > Dim f as Form1 > f.Show > application.run() > end sub and form2 should open and vice versa. Thanks for the reply Karan Show quoteHide quote "Armin Zingler" <az.nospam@freenet.de> wrote in message news:%23TtsTG2QGHA.4452@TK2MSFTNGP12.phx.gbl... > "Karan" <karan***@hotmail.com> schrieb >> I am calling finalize when form2 loads and deactivates form1 which > > > You must never call Finalize. This is done by the GC immediatelly before > destroying the object. To close a Form, call it's close method only. If > you don't need the Form instance anymore, remove the reference. Later, > whenever the GC does it's work, the Form object is destroyed. > > >> 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) > > > Public Sub CloseForm(formType As System.Type) > For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren > If oForm.GetType() Is formType Then '<----- "=" replaced by "Is" > oForm.Close() > Next > End Sub > > > Calling oForm.Dispose() is not necessary because it is called anyway > whenever the Form is closed. > > > 'how to use? > ' CloseForm(TypeOf Form3) > > CloseForm(GetType(Form3)) > >> ###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 > > > I do not completely understand what's your intention: > > The code in Form1.btnShow_Click looks ok. Delete subs Form1_Deactivate and > Form2_Deactivate. In Form2.btnShow_Click, there seems to be a "frm.Show" > missing. > > Looking at btnShow_Click: Do you want to close Form1 if you open Form2, > and close Form2 if you open Form1? Then you should add Me.Close in > btnShow_Click after showing the other Form. If there is no Form that will > live from the start till the end of the application, use this Sub Main: > > Sub Main 'In a Module. In a Class, use Shared Sub Main > Dim f as Form1 > f.Show > application.run() > end sub > > > Armin "Karan" <karan***@hotmail.com> schrieb Sorry, I forgot this one here:> Hi Armin > > f.show() is giving me error nullreferance > > Sub Main 'In a Module. In a Class, use Shared Sub Main Dim f as > > Form1 f = New Form1 >> f.Show Armin>> application.run() >> end sub > > There is a button on form1 show, on click of that button form1 should > close and form2 should open and vice versa.
Print pdf from Internet Explorer using VB .NET
Extending the TreeNode - - -> HELP! need ideas on multi threaded db update get a listing of assemblies from GAC ? "Specified cast is not valid" converting from object A to object B Best Way to Import Fixed Width Files convert string array to long array XML Help wanted Copying a project... How to load AVI's from shell32.dll & play them? |
|||||||||||||||||||||||