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. How to Unhide the Hidden form

How to Unhide the Hidden form

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
10 Posts 5 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.
  • R Offline
    R Offline
    Ravindra Bisen
    wrote on last edited by
    #1

    Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:

    OriginalGriffO D L 3 Replies Last reply
    0
    • R Ravindra Bisen

      Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up. Instead, either 1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling. or 2) Use R1.ShowDialog(); instead of R1.Show(); This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      L 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up. Instead, either 1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling. or 2) Use R1.ShowDialog(); instead of R1.Show(); This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        OriginalGriff wrote:

        it will be disposed later when the CG gets round to it.

        Nah. I don't expect Christian flies around the world collecting our junk. :-D

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        D OriginalGriffO 2 Replies Last reply
        0
        • R Ravindra Bisen

          Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Handle the FormClosing event of R1 in frmstart and it can unhide itself.

          // Different variable names used than in question!
          using System;
          using System.Windows.Forms;

          public partial class FormStart : Form
          {
          public FormStart()
          {
          InitializeComponent();
          // Clicking the form will launch the reader
          Click += new EventHandler(FormStart_Click);
          }

          private void FormStart\_Click(object sender, EventArgs e)
          {
              ShowFormReader();
          }
          private void ShowFormReader()
          {
              FormReader formReader = new FormReader();
              formReader.FormClosing += new FormClosingEventHandler(formReader\_FormClosing);
              formReader.Show();
              Hide();
          }
          private void formReader\_FormClosing(object sender, FormClosingEventArgs e)
          {
              Show();
          }
          

          }

          If it's not a close of R1 that triggers this then you can easily create a custom event and handle that.

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          H 1 Reply Last reply
          0
          • L Luc Pattyn

            OriginalGriff wrote:

            it will be disposed later when the CG gets round to it.

            Nah. I don't expect Christian flies around the world collecting our junk. :-D

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            Good spot! :laugh:

            Dave
            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            1 Reply Last reply
            0
            • L Luc Pattyn

              OriginalGriff wrote:

              it will be disposed later when the CG gets round to it.

              Nah. I don't expect Christian flies around the world collecting our junk. :-D

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Luc Pattyn wrote:

              I don't expect Christian flies around the world collecting our junk.

              He can't - all airlines suck today :-D

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • R Ravindra Bisen

                Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Dave's approach is fine. Maybe a simpler approach is also acceptable: if the one form is hidden while the other is shown, the latter probably could be shown as a dialog, hence:

                this.Hide();
                otherForm.ShowDialog();
                this.Show();

                :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                1 Reply Last reply
                0
                • D DaveyM69

                  Handle the FormClosing event of R1 in frmstart and it can unhide itself.

                  // Different variable names used than in question!
                  using System;
                  using System.Windows.Forms;

                  public partial class FormStart : Form
                  {
                  public FormStart()
                  {
                  InitializeComponent();
                  // Clicking the form will launch the reader
                  Click += new EventHandler(FormStart_Click);
                  }

                  private void FormStart\_Click(object sender, EventArgs e)
                  {
                      ShowFormReader();
                  }
                  private void ShowFormReader()
                  {
                      FormReader formReader = new FormReader();
                      formReader.FormClosing += new FormClosingEventHandler(formReader\_FormClosing);
                      formReader.Show();
                      Hide();
                  }
                  private void formReader\_FormClosing(object sender, FormClosingEventArgs e)
                  {
                      Show();
                  }
                  

                  }

                  If it's not a close of R1 that triggers this then you can easily create a custom event and handle that.

                  Dave
                  Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                  H Offline
                  H Offline
                  Hum Dum
                  wrote on last edited by
                  #8

                  WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)

                  FormReader formReader = new FormReader(this);

                  Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did

                  private void formReader_FormClosing(object sender, FormClosingEventArgs e)
                  {
                  //access member of FormReader
                  }

                  But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like

                  interface IA
                  {
                  void M();
                  }

                  interface IB
                  {
                      void M();
                  }
                  
                  class ABC : IA, IB
                  {
                      public void M()
                      {
                          MessageBox.Show("Hello");
                      }
                  }
                  

                  ABC a = new ABC();
                  a.M();

                  Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB

                  D 2 Replies Last reply
                  0
                  • H Hum Dum

                    WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)

                    FormReader formReader = new FormReader(this);

                    Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did

                    private void formReader_FormClosing(object sender, FormClosingEventArgs e)
                    {
                    //access member of FormReader
                    }

                    But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like

                    interface IA
                    {
                    void M();
                    }

                    interface IB
                    {
                        void M();
                    }
                    
                    class ABC : IA, IB
                    {
                        public void M()
                        {
                            MessageBox.Show("Hello");
                        }
                    }
                    

                    ABC a = new ABC();
                    a.M();

                    Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB

                    D Offline
                    D Offline
                    DaveyM69
                    wrote on last edited by
                    #9

                    With regard to your first question - getting data from FormReader to FormStart: Do NOT use method A. It works but it is a nasty hack that as things get more complex you will regret! Method B does not require any change to the access modifier of FormReader. The sender parameter will (normally) be the FormReader instance. So, inside the handler add something like this:

                    FormReader formReader = sender as FormReader;
                    if(formReader != null)
                    {
                    // You can now use formReader. to access any properties/methods
                    }

                    There is another method if you want FormReader to inform FormStart that there is data it may be interested in - you can raise a custom event in FormReader and subscribe to that in FormStart. Have a look at this tip[^], this tip[^], then this article[^] if this would fit your case better.

                    Dave
                    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                    1 Reply Last reply
                    0
                    • H Hum Dum

                      WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)

                      FormReader formReader = new FormReader(this);

                      Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did

                      private void formReader_FormClosing(object sender, FormClosingEventArgs e)
                      {
                      //access member of FormReader
                      }

                      But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like

                      interface IA
                      {
                      void M();
                      }

                      interface IB
                      {
                          void M();
                      }
                      
                      class ABC : IA, IB
                      {
                          public void M()
                          {
                              MessageBox.Show("Hello");
                          }
                      }
                      

                      ABC a = new ABC();
                      a.M();

                      Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB

                      D Offline
                      D Offline
                      DaveyM69
                      wrote on last edited by
                      #10

                      Sorry, forgot your second question! The answer is neither. An interface has no implementation so you never actually use any methods/properties/events they appear to have. You always use the implementation in the class that provides the implementation.

                      Dave
                      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                      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