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. Form disappearing

Form disappearing

Scheduled Pinned Locked Moved C#
graphicshelpworkspace
13 Posts 4 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.
  • U User 2387889

    Hi All Would appreciate some help on the following code which results in the form disappearing, rather than persisiting. Probably something really silly (code newbie, please be gentle). using System.ComponentModel; using System.Drawing; using System.IO; using System.Windows.Forms; namespace TCPReader { public class frmConfiguration : System.Windows.Forms.Form { private void frmConfiguration_Load(object sender, System.EventArgs e) { } private System.Windows.Forms.Button btnok; private System.Windows.Forms.Button button2; private System.ComponentModel.IContainer components; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; public USBReader.readerqueue m_queue; public USBReader.Socketclient m_sclient; public System.Threading.Thread thread1; public System.Threading.Thread threadClient; private System.Windows.Forms.TextBox txtipaddres; private System.Windows.Forms.TextBox txtportno; private void btnok_Click(object sender, System.EventArgs e) { try { bool flag = txtipaddres.Text != "" && txtportno.Text != ""; if (!flag) { System.Windows.Forms.MessageBox.Show("Enter IP Address and Port No to Connet\n to the Node", "Node Control", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); Show(); } else { System.IO.TextWriter textWriter = System.IO.File.CreateText(System.Windows.Forms.Application.StartupPath + "\\IPAddress.txt"); textWriter.WriteLine(txtportno.Text + ";" + txtipaddres.Text); textWriter.Close(); DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } } catch (System.Exception e1) { } } private void button2_Click(object sender, System.EventArgs e) { DialogResult = System.Windows.Forms.DialogResult.Cancel; Close(); } private void Configuration_Load(object sende

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

    You don't tell us when it disappears, but if it's when you press a button then it's because you told it to:

    private void btnok_Click(object sender, System.EventArgs e)
    {
    try
    {
    bool flag = txtipaddres.Text != "" && txtportno.Text != "";
    if (!flag)
    {
    System.Windows.Forms.MessageBox.Show("Enter IP Address and Port No to Connet\n to the Node", "Node Control", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
    Show();
    }
    else
    {
    System.IO.TextWriter textWriter = System.IO.File.CreateText(System.Windows.Forms.Application.StartupPath + "\\IPAddress.txt");
    textWriter.WriteLine(txtportno.Text + ";" + txtipaddres.Text);
    textWriter.Close();
    DialogResult = System.Windows.Forms.DialogResult.OK;
    Close();
    }
    }
    catch (System.Exception e1)
    {
    }
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
    DialogResult = System.Windows.Forms.DialogResult.Cancel;
    Close();
    }

    That's what Form.Close does: closes the current form. BTW: Don't swallow your exceptions: they mean you don't find out why it failed (or that it failed in this case). Report 'em, log 'em, whatever. But empty catch blocks don't help anyone - least of all you.

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    "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

    U 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      You don't tell us when it disappears, but if it's when you press a button then it's because you told it to:

      private void btnok_Click(object sender, System.EventArgs e)
      {
      try
      {
      bool flag = txtipaddres.Text != "" && txtportno.Text != "";
      if (!flag)
      {
      System.Windows.Forms.MessageBox.Show("Enter IP Address and Port No to Connet\n to the Node", "Node Control", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
      Show();
      }
      else
      {
      System.IO.TextWriter textWriter = System.IO.File.CreateText(System.Windows.Forms.Application.StartupPath + "\\IPAddress.txt");
      textWriter.WriteLine(txtportno.Text + ";" + txtipaddres.Text);
      textWriter.Close();
      DialogResult = System.Windows.Forms.DialogResult.OK;
      Close();
      }
      }
      catch (System.Exception e1)
      {
      }
      }

      private void button2_Click(object sender, System.EventArgs e)
      {
      DialogResult = System.Windows.Forms.DialogResult.Cancel;
      Close();
      }

      That's what Form.Close does: closes the current form. BTW: Don't swallow your exceptions: they mean you don't find out why it failed (or that it failed in this case). Report 'em, log 'em, whatever. But empty catch blocks don't help anyone - least of all you.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      U Offline
      U Offline
      User 2387889
      wrote on last edited by
      #3

      Thanks OriginalGriff Apologies, should have made my description clearer, the form never actually appears (or if it does then it quickly disappears), it is the only form currently and I am not entering / selecting anything (I don't get the chance). Any thoughts appreciated. Regards Active

      OriginalGriffO P 2 Replies Last reply
      0
      • U User 2387889

        Thanks OriginalGriff Apologies, should have made my description clearer, the form never actually appears (or if it does then it quickly disappears), it is the only form currently and I am not entering / selecting anything (I don't get the chance). Any thoughts appreciated. Regards Active

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

        So what code are you displaying it with?

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "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

        U 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          So what code are you displaying it with?

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          U Offline
          U Offline
          User 2387889
          wrote on last edited by
          #5

          I had expected that the following should make the form appear -

          private void frmConfiguration_Load(object sender, System.EventArgs e)
          {
          }

          private void InitializeComponent()
          {
          this.label1 = new System.Windows.Forms.Label();
          this.label2 = new System.Windows.Forms.Label();
          this.btnok = new System.Windows.Forms.Button();

          etc ... Regards Active

          OriginalGriffO 1 Reply Last reply
          0
          • U User 2387889

            I had expected that the following should make the form appear -

            private void frmConfiguration_Load(object sender, System.EventArgs e)
            {
            }

            private void InitializeComponent()
            {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.btnok = new System.Windows.Forms.Button();

            etc ... Regards Active

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

            :laugh: No - what code makes the form display? Are you creating it in Main (in process.cs)? Or do you display it from an existing form?

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "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

            U 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              :laugh: No - what code makes the form display? Are you creating it in Main (in process.cs)? Or do you display it from an existing form?

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              U Offline
              U Offline
              User 2387889
              wrote on last edited by
              #7

              Thanks, I was missing the .Run in main, thought it was something silly. The form now appears but it is blank (no text, fields etc displaying), probably something else missing. Regards Active

              OriginalGriffO 2 Replies Last reply
              0
              • U User 2387889

                Thanks, I was missing the .Run in main, thought it was something silly. The form now appears but it is blank (no text, fields etc displaying), probably something else missing. Regards Active

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

                I don't see any form constructor in your code? So what is calling InitializeComponent - if you don't call that in a constructor, then there will be nothing to show!

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "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

                U 1 Reply Last reply
                0
                • U User 2387889

                  Thanks, I was missing the .Run in main, thought it was something silly. The form now appears but it is blank (no text, fields etc displaying), probably something else missing. Regards Active

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

                  BTW: Are you creating all this by hand? If so, why? You do realise that VS can create a "tidier" version of all that for you automatically?

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  "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
                  • OriginalGriffO OriginalGriff

                    I don't see any form constructor in your code? So what is calling InitializeComponent - if you don't call that in a constructor, then there will be nothing to show!

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                    U Offline
                    U Offline
                    User 2387889
                    wrote on last edited by
                    #10

                    As you say the form constructor was missing (previously created by another form), silly me, again. Now working. I appreciate your help OriginalGriff, thanks again. Regards Active

                    OriginalGriffO 1 Reply Last reply
                    0
                    • U User 2387889

                      As you say the form constructor was missing (previously created by another form), silly me, again. Now working. I appreciate your help OriginalGriff, thanks again. Regards Active

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

                      You're welcome!

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                      "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
                      • U User 2387889

                        Thanks OriginalGriff Apologies, should have made my description clearer, the form never actually appears (or if it does then it quickly disappears), it is the only form currently and I am not entering / selecting anything (I don't get the chance). Any thoughts appreciated. Regards Active

                        P Offline
                        P Offline
                        Philippe Mori
                        wrote on last edited by
                        #12

                        Then where is the code to display the form? It won't appears magically... (except for the initial form which is initialized by the application).

                        Philippe Mori

                        1 Reply Last reply
                        0
                        • U User 2387889

                          Hi All Would appreciate some help on the following code which results in the form disappearing, rather than persisiting. Probably something really silly (code newbie, please be gentle). using System.ComponentModel; using System.Drawing; using System.IO; using System.Windows.Forms; namespace TCPReader { public class frmConfiguration : System.Windows.Forms.Form { private void frmConfiguration_Load(object sender, System.EventArgs e) { } private System.Windows.Forms.Button btnok; private System.Windows.Forms.Button button2; private System.ComponentModel.IContainer components; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; public USBReader.readerqueue m_queue; public USBReader.Socketclient m_sclient; public System.Threading.Thread thread1; public System.Threading.Thread threadClient; private System.Windows.Forms.TextBox txtipaddres; private System.Windows.Forms.TextBox txtportno; private void btnok_Click(object sender, System.EventArgs e) { try { bool flag = txtipaddres.Text != "" && txtportno.Text != ""; if (!flag) { System.Windows.Forms.MessageBox.Show("Enter IP Address and Port No to Connet\n to the Node", "Node Control", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); Show(); } else { System.IO.TextWriter textWriter = System.IO.File.CreateText(System.Windows.Forms.Application.StartupPath + "\\IPAddress.txt"); textWriter.WriteLine(txtportno.Text + ";" + txtipaddres.Text); textWriter.Close(); DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } } catch (System.Exception e1) { } } private void button2_Click(object sender, System.EventArgs e) { DialogResult = System.Windows.Forms.DialogResult.Cancel; Close(); } private void Configuration_Load(object sende

                          C Offline
                          C Offline
                          ChizI
                          wrote on last edited by
                          #13

                          Please let me know the name of your software so I never use it. Anything with a namespace of TCPReader, but you don't know how to figure out why a form isn't appearing, is very scary.

                          -- Chizl

                          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