C# accessing components of an Object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harvindersingh
    New Member
    • Sep 2008
    • 24

    C# accessing components of an Object

    Hello guys,

    I am trying to access components of object created suring runtime. Basically the object is a new form and I call it like this:

    Code:
                QuickUpdate qu = new QuickUpdate();
                MessageBox.Show(qu.markedToEditLabel.Visible.ToString());
    The markedToEditLab el is a label and not visible by defualt, the QuickUpdate class uses ShowDialogue method to display the form. While the QuickUpdate form is open I change the visibility of the markedToEditLab el label to true and close the form. The closing of the form is performed by the Hide method placed in the QuickUpdate form it self. Once the form is exited, I would like to find out if the markedToEditLab el label was switched to visible. I checked this with the second line in the code in the MessageBox. However it seems to be forwarding false all the time, even though the visibility was changed to true before closing the QuickUpdate form.

    Is there anything I am not doing correctly, or am I just trying to achieve something which is not possible!

    Thanks in advance.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Well, I think if you hide the form, everything becomes invisible maybe? Anyway, if I were you, I'd set a public bool property that you changed every time you change that label's visibility. Then retrieve that value.

    Comment

    • matthewaveryusa
      New Member
      • Jul 2008
      • 20

      #3
      Intersting question:
      I created a little test bench and you will need to do what the above post says: when you hide the form, all the controls get their visible property set to false.

      Code:
              private void button1_Click(object sender, EventArgs e)
              {
                  if (label1.Visible == true)
                  {
                      label1.Visible = false;
                  }
                  else
                  {
                      label1.Visible = true;
                  }
              }
      
              private void button2_Click(object sender, EventArgs e)
              {
                  Hide();
                  MessageBox.Show(label1.Visible.ToString(),"label1 Visible?",MessageBoxButtons.OK);
                  Show();
              }
      
              private void button3_Click(object sender, EventArgs e)
              {
                  MessageBox.Show(label1.Visible.ToString(), "label1 Visible?", MessageBoxButtons.OK);
              }
      button 1 toggles the visibility of label1.
      when I press button 2, which hides the form, the MB reports false.
      when I press button3, which doesn't hide the form, the visibility of label1 is properly reported.

      Comment

      • harvindersingh
        New Member
        • Sep 2008
        • 24

        #4
        Great thanks

        By using a Public bool was the solution of the problem. Yes apparently when the form is closed all of the drawing components gets false for their visibility. I was actually just trying the first approach because I want to keep the classes as small as possible by using the already created resources, this way it is less confusing.

        The whole reason of making the code as little as possible is because the project I am working on is rather big and I am doing this on a personal software so I am the only person who will have to keep the code in working condition all the time.

        Thanks again for the help

        Comment

        Working...