Connecting Tech Pros Worldwide Forums | Help | Site Map

C# accessing components of an Object

Newbie
 
Join Date: Sep 2008
Location: London, England
Posts: 24
#1: Oct 24 '08
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:

Expand|Select|Wrap|Line Numbers
  1.             QuickUpdate qu = new QuickUpdate();
  2.             MessageBox.Show(qu.markedToEditLabel.Visible.ToString());
  3.  
The markedToEditLabel 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 markedToEditLabel 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 markedToEditLabel 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.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Oct 24 '08

re: C# accessing components of an Object


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.
Newbie
 
Join Date: Jul 2008
Posts: 20
#3: Oct 24 '08

re: C# accessing components of an Object


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.

Expand|Select|Wrap|Line Numbers
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             if (label1.Visible == true)
  4.             {
  5.                 label1.Visible = false;
  6.             }
  7.             else
  8.             {
  9.                 label1.Visible = true;
  10.             }
  11.         }
  12.  
  13.         private void button2_Click(object sender, EventArgs e)
  14.         {
  15.             Hide();
  16.             MessageBox.Show(label1.Visible.ToString(),"label1 Visible?",MessageBoxButtons.OK);
  17.             Show();
  18.         }
  19.  
  20.         private void button3_Click(object sender, EventArgs e)
  21.         {
  22.             MessageBox.Show(label1.Visible.ToString(), "label1 Visible?", MessageBoxButtons.OK);
  23.         }
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.
Newbie
 
Join Date: Sep 2008
Location: London, England
Posts: 24
#4: Oct 24 '08

re: C# accessing components of an Object


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
Reply