dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: ReInitialize program

  1. #16
    Join Date
    Jan 2006
    Posts
    293

    Re: ReInitialize program

    I dont understand what the problem is. Button 2, when you click it, closes the form. The reason it was starting a new instance of form1 when you were closing it before is because you were using BUTTON 1 to close it (I assume), since by clicking button 1, it closes the form (when you had me.close) and restarts form 1 using the RestartMainForm sub.

    If you want to close the form, close the form (calling me.close). If you want to re-initialize form1, then call RestartMainForm. You were doing both of those things, and wondering why it was starting a new instance when you were closing the form. The reason it was doing it was because you coded it to (with a me.close call and then a call to restartmainform).

  2. #17
    Join Date
    Oct 2006
    Posts
    449

    Re: ReInitialize program

    gigemboy: Thank you fr your post. Let me explain you clearly. Please bear with me.

    Button2 - Am not using it at all. And as you had mentioned I don't have me.close() in my Button1 event NOW.

    (If you want to close the form, close the form (calling me.close). If you want to re-initialize form1, then call RestartMainForm. )

    I have my module as displayed below:
    -------------------------------------------
    Module RestartMainForm1

    Public Sub RestartMainForm(ByVal CallingForm As Form1)
    Dim MyNewForm As New Form1
    MyNewForm.Show()
    CallingForm.Close()
    End Sub
    End Module
    -------------------------------------------

    I have the code 'RestartMainForm(Form1) in my Form2 under Button1.click event as mentioned below:

    -------------------------------------------
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MessageBox.Show("Data updated!!", "My App")
    RestartMainForm(Form1)

    End Sub
    -------------------------------------------

    So what happens NOW is, I click on 'Form2' link in 'Form1' which is also my main start page and then after actions I click on Button1... it displays 'Data updated!!' and restarts 'Form1' but 'Form2' is still open and you can find it in task bar. How do you close 'Form2' now? And if I click on 'Form2' link in my 'Form1' again there's an exception error. But if I open the 'Form2' which is already still open by clicking on task bar then 'Form1' opens as new instance. Hope am clear. Am still doing it wrong somewhere. I kindly request you to bear with me and guide me. Thank you.

  3. #18
    Join Date
    Jan 2006
    Posts
    293

    Re: ReInitialize program

    You can close form2 by putting a me.close after you call restartmainform from form2, if that is when you wish to close it. In regards to your question about form2 showing an error when you click the link on form1, then what code are you using for that? You should be checking to see if form2 exists, and if not, create a new instance and show it (or just create a new instance and show it every time if you are closing it every time)

  4. #19
    Join Date
    Oct 2006
    Posts
    449

    Smile Re: ReInitialize program

    gigemboy... finally it is working! Thank you for all your time and patience. Now I have a another query. I have 'Button1' which on clicking displays 'Data updated!', closes and then restartsmainform. And now I have changed 'Button2' to Reset all the fields in the form and I have added 'controlbox' to the form for the user to close the form if he doesn't want to perform any actions. NOW WHEN I CLICK ON THE CONTROLBOX TO CLOSE THE FORM, THE WHOLE APPLICATION CLOSES. HOW / WHAT SHOULD I USE TO CLOSE THE FORM ALONE NOW?

  5. #20
    Join Date
    Oct 2006
    Posts
    449

    Re: ReInitialize program

    gigemboy... am waiting for your reply. Now all is fine. The main form restarts and form2 gets reset but when I close my form2 using controlbox the application itself closes instead of closing the form. How do I control that. Please have a look at my previous post for more detailed information. Please help/guide me through. Thank you.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)