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. Need Help With Win Forms

Need Help With Win Forms

Scheduled Pinned Locked Moved C#
helpquestion
6 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.
  • D Offline
    D Offline
    DRAYKKO
    wrote on last edited by
    #1

    I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:

    if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
    {
    //TODO1: set up logic for authentic use
    copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
    }

    This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---

    ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

    M C 2 Replies Last reply
    0
    • D DRAYKKO

      I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:

      if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
      {
      //TODO1: set up logic for authentic use
      copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
      }

      This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---

      ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

      M Offline
      M Offline
      Muammar
      wrote on last edited by
      #2

      if(!false) // if true
      {
      dadada dada...
      }

      what's so "logically incorrect"??


      Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

      1 Reply Last reply
      0
      • D DRAYKKO

        I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:

        if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
        {
        //TODO1: set up logic for authentic use
        copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
        }

        This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---

        ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        DRAYKKO wrote:

        I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false.

        You're probably setting the property on a different instance of the form. Can you post that code ? The code that sets the value of Authenticated user is what we really need to see here, I suspect.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        D 1 Reply Last reply
        0
        • C Christian Graus

          DRAYKKO wrote:

          I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false.

          You're probably setting the property on a different instance of the form. Can you post that code ? The code that sets the value of Authenticated user is what we really need to see here, I suspect.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

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

          private void OK_Click(object sender, EventArgs e)
          {
          //use this to confirm that the user is valid
          Main userAuthentication = new Main();

                  userAuthentication.AuthenticUser = CheckUser();
          
                  if (userAuthentication.AuthenticUser)
                  {
                      this.Close();
                  }
                  else 
                  {
                      if (Tries < 2)
                      {
                          MessageBox.Show("That was an invalid user name or password. Try again...");
                          ++Tries;
                          CheckUser();
                      }
                      else
                      {
                          userAuthentication.AuthenticUser = false;
                          this.Close();
                      }
                  } 
              }
          
              public bool CheckUser()
              {
                  //testing number of tries
                  //string numberOfTries = string.Format("tries = {0}", Tries);
                  //MessageBox.Show(numberOfTries);
          
                  if ((usernameTextBox.Text == "User1") && (passwordTextBox.Text == "User1"))
                      return true;
                  else if ((usernameTextBox.Text == "User2") && (passwordTextBox.Text == "User2"))
                      return true;
                  else
                  {
                      usernameTextBox.Text = "";
                      passwordTextBox.Text = "";
                      usernameTextBox.Focus();
                      return false;
                  }
              }
          

          This code, from the Logon form, is supposed to alert the Main form whether the user typed in a valid username and password. And when I "trace" it, it does set AuthenicUser to true. But it seems that when I close the logon form the property reverts back to false (and I'm not sure why). BTW: Is there a way to send attachments here?

          ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

          C 1 Reply Last reply
          0
          • D DRAYKKO

            private void OK_Click(object sender, EventArgs e)
            {
            //use this to confirm that the user is valid
            Main userAuthentication = new Main();

                    userAuthentication.AuthenticUser = CheckUser();
            
                    if (userAuthentication.AuthenticUser)
                    {
                        this.Close();
                    }
                    else 
                    {
                        if (Tries < 2)
                        {
                            MessageBox.Show("That was an invalid user name or password. Try again...");
                            ++Tries;
                            CheckUser();
                        }
                        else
                        {
                            userAuthentication.AuthenticUser = false;
                            this.Close();
                        }
                    } 
                }
            
                public bool CheckUser()
                {
                    //testing number of tries
                    //string numberOfTries = string.Format("tries = {0}", Tries);
                    //MessageBox.Show(numberOfTries);
            
                    if ((usernameTextBox.Text == "User1") && (passwordTextBox.Text == "User1"))
                        return true;
                    else if ((usernameTextBox.Text == "User2") && (passwordTextBox.Text == "User2"))
                        return true;
                    else
                    {
                        usernameTextBox.Text = "";
                        passwordTextBox.Text = "";
                        usernameTextBox.Focus();
                        return false;
                    }
                }
            

            This code, from the Logon form, is supposed to alert the Main form whether the user typed in a valid username and password. And when I "trace" it, it does set AuthenicUser to true. But it seems that when I close the logon form the property reverts back to false (and I'm not sure why). BTW: Is there a way to send attachments here?

            ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            DRAYKKO wrote:

            Main userAuthentication = new Main();

            Like I thought. You're creating a new instance of the Main class, which has absolutely NOTHING to do with the instance in which you check this variable. You should create a variable inside this form and check it from your main instance, when you close the login dialog. Or, set up a delegate that gets called if login is successful.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            D 1 Reply Last reply
            0
            • C Christian Graus

              DRAYKKO wrote:

              Main userAuthentication = new Main();

              Like I thought. You're creating a new instance of the Main class, which has absolutely NOTHING to do with the instance in which you check this variable. You should create a variable inside this form and check it from your main instance, when you close the login dialog. Or, set up a delegate that gets called if login is successful.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              D Offline
              D Offline
              DRAYKKO
              wrote on last edited by
              #6

              Thank you Christian! I see the problem now. :doh: As a solution I made the property and it's subsequent variable static bool (rather than just bool), so that they were accessible from the Logon form. Thanks for your input, and help!! :) Dre---

              ======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science

              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