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. want to open a single copy of a form on a event

want to open a single copy of a form on a event

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 2 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.
  • I Offline
    I Offline
    imsathy
    wrote on last edited by
    #1

    Hi all.... i want to open form on a event. if form is already opened it should not open again on that event else should open again. for example i tried for a button click event ... // member of form1 class Form2 obj = new Form2(); private void button1_Click(object sender, System.EventArgs e) { obj.Show(); } 1) if i declare the form2 obj inside the function its opening a new copy of form2 for each click event 2) or if i declare it as a member of form1 class and if i close the form2 and againg tried to open it, it throws the foll.. exception... An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll Additional information: Cannot access a disposed object named "Form1". :confused: sathy

    M 1 Reply Last reply
    0
    • I imsathy

      Hi all.... i want to open form on a event. if form is already opened it should not open again on that event else should open again. for example i tried for a button click event ... // member of form1 class Form2 obj = new Form2(); private void button1_Click(object sender, System.EventArgs e) { obj.Show(); } 1) if i declare the form2 obj inside the function its opening a new copy of form2 for each click event 2) or if i declare it as a member of form1 class and if i close the form2 and againg tried to open it, it throws the foll.. exception... An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll Additional information: Cannot access a disposed object named "Form1". :confused: sathy

      M Offline
      M Offline
      Maqsood Ahmed
      wrote on last edited by
      #2

      Hello, You can try following code. Define the Form2 object outside the function as 'global' variable for the Form1 class. Form2 obj; ..... Write this code in the button click event handler private void button1_Click(object sender, System.EventArgs e) { if(obj == null || obj.IsDisposed) obj = new Form2(); obj.Show(); } HTH. Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net

      I 1 Reply Last reply
      0
      • M Maqsood Ahmed

        Hello, You can try following code. Define the Form2 object outside the function as 'global' variable for the Form1 class. Form2 obj; ..... Write this code in the button click event handler private void button1_Click(object sender, System.EventArgs e) { if(obj == null || obj.IsDisposed) obj = new Form2(); obj.Show(); } HTH. Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net

        I Offline
        I Offline
        imsathy
        wrote on last edited by
        #3

        thankzzzz a lot Masqood:cool: superb!!!! sathy

        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