CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Location
    Somewhere, Texas
    Posts
    1

    Using a string to access a label?

    Hi all and thanks for taking a look at my problem. I apologize if my question isn't exactly clear.

    I am using .NET 1.1 VS 2003.

    I would like to be able to set the text of a label using two separate strings. The best way I can describe what I would like to do is something like
    "label1".text = otherString;
    Where "label1" and otherString are both string objects.

    "label1" (n-1) is a string that occurs in an array of strings immediately before otherString (n). So I am wanting to loop through this array, check each odd array element, use that string to access a label and set the text of that label with the next even array element.

    I have found some things like System.Reflection. Is this the correct way to go about doing what I am trying to do? Is there a better way of doing this? Can it even be done?

    Thanks!

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: Using a string to access a label?

    First of all you need to know what the parent control is, then use "ParentControl.Controls.Find()" to get the control. If the label control is just a child of form, use "this.Controls.Find()".

    Hope it helps.
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured