Get a label value from a MDI child form

  • Thread starter Thread starter Steve Ricketts
  • Start date Start date
S

Steve Ricketts

I'm obviously new at C# and this question is more about the language than
the example. I have a MDI child and I want to get/set a label (labIndex)
value on another child form. I have:

private string labIndex
{
get {return labIndex.value; }
set {labIndex.value = value; }
}

public static string getIndex()
{
return labIndex; << but this can't be seen because it's inside a static
method
}

So, how to I get and set the labIndex.value??

Thanks in advance!
 
I'm obviously new at C# and this question is more about the language
than the example. I have a MDI child and I want to get/set a label
(labIndex) value on another child form. I have:

private string labIndex
{
get {return labIndex.value; }
set {labIndex.value = value; }
}

public static string getIndex()
{
return labIndex; << but this can't be seen because it's inside a static
method
}

So, how to I get and set the labIndex.value??

Thanks in advance!

Make the property public, and you call the form instance object's
property. Like this:

Form1 ui = new Form1();
ui.labIndex = "Hi!";
 
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like: frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's not
the right way to do it.

sr
 
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like: frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's
not the right way to do it.

sr


Your array is declared as an array of Form objects, not an array of
frmStudent objects. For this reason, labName does not show. It would
be necessary to declare the array as:

public static frmStudent [] frmPerson = new frmStudent [16];
 
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like: frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's
not the right way to do it.

sr


Your array is declared as an array of Form objects, not an array of
frmStudent objects. For this reason, labName does not show. It would be
necessary to declare the array as:

public static frmStudent [] frmPerson = new frmStudent [16];

Sorry, you could cast frmPerson back to a frmStudent when you need
labName, keeping the original declaration.
 
Sorry for the blond moment but which original declaration?... mine or yours?
;-)

sr

Family Tree Mike said:
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like: frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's
not the right way to do it.

sr


Your array is declared as an array of Form objects, not an array of
frmStudent objects. For this reason, labName does not show. It would be
necessary to declare the array as:

public static frmStudent [] frmPerson = new frmStudent [16];

Sorry, you could cast frmPerson back to a frmStudent when you need
labName, keeping the original declaration.
 
Sorry for the blond moment but which original declaration?... mine or
yours? ;-)

sr

Family Tree Mike said:
On 12/13/2009 4:46 PM, Steve Ricketts wrote:
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like:
frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's
not the right way to do it.

sr



Your array is declared as an array of Form objects, not an array of
frmStudent objects. For this reason, labName does not show. It would be
necessary to declare the array as:

public static frmStudent [] frmPerson = new frmStudent [16];

Sorry, you could cast frmPerson back to a frmStudent when you need
labName, keeping the original declaration.

Yours...

You could have done:
public static Form[] frmPerson = new frmStudent[16];

then later:
((frmStudent) frmMain.frmPerson[0]).labName;
 
Thanks, that worked great. Seems I'm having all sorts of issues on
visibility of things.

sr

Family Tree Mike said:
Sorry for the blond moment but which original declaration?... mine or
yours? ;-)

sr

Family Tree Mike said:
On 12/13/2009 6:16 PM, Family Tree Mike wrote:
On 12/13/2009 4:46 PM, Steve Ricketts wrote:
Actually, I have created the forms publically:

public static Form[] frmPerson = new frmStudent[16];

But the labels are not visible from something like:
frmPerson[0].labName

I have found that I can get to the labels in each form by using
frmMain.frmPerson[0].Controls["labName"].Text but I'm guessing that's
not the right way to do it.

sr



Your array is declared as an array of Form objects, not an array of
frmStudent objects. For this reason, labName does not show. It would be
necessary to declare the array as:

public static frmStudent [] frmPerson = new frmStudent [16];



Sorry, you could cast frmPerson back to a frmStudent when you need
labName, keeping the original declaration.

Yours...

You could have done:
public static Form[] frmPerson = new frmStudent[16];

then later:
((frmStudent) frmMain.frmPerson[0]).labName;
 
Back
Top