locked
Label() RRS feed

  • Question

  • Arrays of labels seem to have disapeared
    Monday, August 31, 2009 8:02 AM

Answers

  • Control arrays don't really exist in .NET (compatibility aside). But you can make an array at run time if you need to manipulate the labels in an group.

    Private m_Labels(10) As Label

    m_Labels(0) = lblFirstName
    m_Labels(1) = lblLastName
    m_Labels(2) = lblStreet
    etc.

    Now you can loop through the array to do things to the labels.

    You don't use Load to create new controls. Instead just create an instance of the class (New Label()) and set its Parent to whatever should contain it. To destroy a control, set its Parent to Nothing.

    Here's an example that may help:

    http://www.vb-helper.com/howto_net_control_array2.html

    Rod

    Rod Stephens, Visual Basic MVP

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
    • Proposed as answer by jinzai Monday, August 31, 2009 8:50 PM
    • Marked as answer by Jeff Shan Friday, September 4, 2009 7:01 AM
    Monday, August 31, 2009 1:26 PM

All replies

  • The're in the Microsoft.VisualBasic.Compatibility.VB6.LabelArray class.
    Monday, August 31, 2009 9:03 AM
  • Control arrays don't really exist in .NET (compatibility aside). But you can make an array at run time if you need to manipulate the labels in an group.

    Private m_Labels(10) As Label

    m_Labels(0) = lblFirstName
    m_Labels(1) = lblLastName
    m_Labels(2) = lblStreet
    etc.

    Now you can loop through the array to do things to the labels.

    You don't use Load to create new controls. Instead just create an instance of the class (New Label()) and set its Parent to whatever should contain it. To destroy a control, set its Parent to Nothing.

    Here's an example that may help:

    http://www.vb-helper.com/howto_net_control_array2.html

    Rod

    Rod Stephens, Visual Basic MVP

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
    • Proposed as answer by jinzai Monday, August 31, 2009 8:50 PM
    • Marked as answer by Jeff Shan Friday, September 4, 2009 7:01 AM
    Monday, August 31, 2009 1:26 PM