Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Embarrassed - Simple Form Question

Embarrassed - Simple Form Question

Scheduled Pinned Locked Moved C#
csharpquestionc++tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Malcolm Smart
    wrote on last edited by
    #1

    Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.

    D K 2 Replies Last reply
    0
    • M Malcolm Smart

      Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.

      D Offline
      D Offline
      donkaiser
      wrote on last edited by
      #2

      If i get your problem: you wanna open form2 from form1. and then close form2. using this.close(); is good. it will close form2 but not form1. the next time u call form2 again form form1 everything should be refreshed. Donkaiser

      1 Reply Last reply
      0
      • M Malcolm Smart

        Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.

        K Offline
        K Offline
        kasik
        wrote on last edited by
        #3

        Angel1058 wrote:

        'Close()'. Does that destroy the window?

        If you mean will secondform be a null pointer after it's called, then no. Close() disposes the form and it's contents, and destroys it's window handle, but comparing secondform to null (like you're doing in your OnClickEvent() method) will return false. You can use the IsDisposed property of the Form to check to see if the form has been disposed, and that should work (but you'd have to check if it's null first)...

        if ( secondform == null || secondform.IsDisposed )
        secondform = new MyForm(data_for_form_listbox)

        Hope that helps :)


        “Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will H

        M 1 Reply Last reply
        0
        • K kasik

          Angel1058 wrote:

          'Close()'. Does that destroy the window?

          If you mean will secondform be a null pointer after it's called, then no. Close() disposes the form and it's contents, and destroys it's window handle, but comparing secondform to null (like you're doing in your OnClickEvent() method) will return false. You can use the IsDisposed property of the Form to check to see if the form has been disposed, and that should work (but you'd have to check if it's null first)...

          if ( secondform == null || secondform.IsDisposed )
          secondform = new MyForm(data_for_form_listbox)

          Hope that helps :)


          “Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will H

          M Offline
          M Offline
          Malcolm Smart
          wrote on last edited by
          #4

          secondform.IsDisposed

          That's what I was missing - many thanks. Amazing, I've used MFC/VC++ for years and years and yet couldn't even successfully close and reopen a form in C#....doh. Thanks again. Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups