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. accessing control's value from a seperate class.

accessing control's value from a seperate class.

Scheduled Pinned Locked Moved C#
10 Posts 6 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.
  • J Offline
    J Offline
    JollyMansArt
    wrote on last edited by
    #1

    ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

    S M D J L 5 Replies Last reply
    0
    • J JollyMansArt

      ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      One whay is to make those values static. and then it will be shared among all instance of a form

      1 Reply Last reply
      0
      • J JollyMansArt

        ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

        M Offline
        M Offline
        MarkLTX
        wrote on last edited by
        #3

        If the other class has a reference to the form instance, you can either make the two control objects public members of the form class, or add two "get" methods to the form that just return the desired properties of the two control.

        1 Reply Last reply
        0
        • J JollyMansArt

          ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

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

          It depends on the relationship between the class and the form with those controls. If the form instanciates the class then you can set properties in the class when the controls change. If the class instanciates the form then the class can read any custom public properties you create on the form, or better still, the form can raise custom events which the class can subscribe to. If they are only related by a common ancestor, the form can raise events that bubble up to the common ancestor, and that can in turn set a chain of property changes or method calls back down the line to the class.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          1 Reply Last reply
          0
          • J JollyMansArt

            ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

            J Offline
            J Offline
            JollyMansArt
            wrote on last edited by
            #5

            Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value

                    private void EnableDisableSaveChanges(String txtboxName, String txtValue)
                {
                    if (ckbxUniqueName.Checked == true)
                    {
                        if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged)
                        {
                            btnSaveChanges.Enabled = true;
                        }
                        else
                        {
                            btnSaveChanges.Enabled = false;
                        }
                    }
                    else
                    {
                        if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged)
                        {
                            btnSaveChanges.Enabled = true;
                        }
                        else
                        {
                            btnSaveChanges.Enabled = false;
                        }
                    }
            

            This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...

                #region Validate if a change has occured to any of the fields on tab 1.
                ////////////////////////////////////
                private Boolean HastxtAppNameControlValueChanged()
                {
                    if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "")
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                private Boolean HastxtVerNumberControlValueChanged()
                {
                    if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "")
                    {
                        return false;
                    }
                    else
            
            J H 2 Replies Last reply
            0
            • J JollyMansArt

              Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value

                      private void EnableDisableSaveChanges(String txtboxName, String txtValue)
                  {
                      if (ckbxUniqueName.Checked == true)
                      {
                          if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged)
                          {
                              btnSaveChanges.Enabled = true;
                          }
                          else
                          {
                              btnSaveChanges.Enabled = false;
                          }
                      }
                      else
                      {
                          if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged)
                          {
                              btnSaveChanges.Enabled = true;
                          }
                          else
                          {
                              btnSaveChanges.Enabled = false;
                          }
                      }
              

              This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...

                  #region Validate if a change has occured to any of the fields on tab 1.
                  ////////////////////////////////////
                  private Boolean HastxtAppNameControlValueChanged()
                  {
                      if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "")
                      {
                          return false;
                      }
                      else
                      {
                          return true;
                      }
                  }
                  private Boolean HastxtVerNumberControlValueChanged()
                  {
                      if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "")
                      {
                          return false;
                      }
                      else
              
              J Offline
              J Offline
              JollyMansArt
              wrote on last edited by
              #6

              If i change the methods to static functions I can no longer access the form controls. Please help. I believe at least a static function is what I want but I need to be able to access the forms controls values...)

              D 1 Reply Last reply
              0
              • J JollyMansArt

                If i change the methods to static functions I can no longer access the form controls. Please help. I believe at least a static function is what I want but I need to be able to access the forms controls values...)

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

                You almost never want a static function when dealing with an instance, for obvious reasons. Strip out all that code and checking a million different properties/fields/controls/whatever - the same principle applies even if there is just one that needs to be checked. It will then be clearer to both us and you! Unless I missed it somewhere way off screen to the right with all the scrolling, I don't see the relationship between the classes - what instanciates what here?

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
                Why are you using VB6? Do you hate yourself? (Christian Graus)

                J 1 Reply Last reply
                0
                • D DaveyM69

                  You almost never want a static function when dealing with an instance, for obvious reasons. Strip out all that code and checking a million different properties/fields/controls/whatever - the same principle applies even if there is just one that needs to be checked. It will then be clearer to both us and you! Unless I missed it somewhere way off screen to the right with all the scrolling, I don't see the relationship between the classes - what instanciates what here?

                  Dave
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                  Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
                  Why are you using VB6? Do you hate yourself? (Christian Graus)

                  J Offline
                  J Offline
                  JollyMansArt
                  wrote on last edited by
                  #8

                  Here is what I am trying to do... I want to be able to receive a response of true or false when these values change. The Unchanged... is the variable with the current value. without doing if (txtAppName.Text == UnchangedAppNameField) {something...} I want to have something that says if (btxtAppName) {somehting...} or say (This is the way I would like to do it.) if (SomeClass.AreThereAnyChanges) {something} My main problem is I do not know how to access the forms controls from the class.

                  1 Reply Last reply
                  0
                  • J JollyMansArt

                    Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value

                            private void EnableDisableSaveChanges(String txtboxName, String txtValue)
                        {
                            if (ckbxUniqueName.Checked == true)
                            {
                                if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged)
                                {
                                    btnSaveChanges.Enabled = true;
                                }
                                else
                                {
                                    btnSaveChanges.Enabled = false;
                                }
                            }
                            else
                            {
                                if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged)
                                {
                                    btnSaveChanges.Enabled = true;
                                }
                                else
                                {
                                    btnSaveChanges.Enabled = false;
                                }
                            }
                    

                    This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...

                        #region Validate if a change has occured to any of the fields on tab 1.
                        ////////////////////////////////////
                        private Boolean HastxtAppNameControlValueChanged()
                        {
                            if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "")
                            {
                                return false;
                            }
                            else
                            {
                                return true;
                            }
                        }
                        private Boolean HastxtVerNumberControlValueChanged()
                        {
                            if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "")
                            {
                                return false;
                            }
                            else
                    
                    H Offline
                    H Offline
                    Henry Minute
                    wrote on last edited by
                    #9

                    It is too late here for me to make any sense of your problem (my fault, not yours), but your code wouldbe a little shorter and therefore possibly easier to understand if you replace this (and all the ones like it):

                    private Boolean HasckbxMasterApplicationControlValueChanged()
                    {
                        if (ckbxMasterApplication.Checked == UnchangedMasterAppField)
                        {
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    

                    with:

                    private Boolean HasckbxMasterApplicationControlValueChanged()
                    {
                        return !(ckbxMasterApplication.Checked == UnchangedMasterAppField);
                    }
                    

                    or, of course:

                    private Boolean HasckbxMasterApplicationControlValueChanged()
                    {
                        return (ckbxMasterApplication.Checked != UnchangedMasterAppField);
                    }
                    

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                    1 Reply Last reply
                    0
                    • J JollyMansArt

                      ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.

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

                      I agree with Dave and Henry: - static won't help - more compact code could make it manageable. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                      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