Need to change properties of control with same name as string variable

Posted on 2006-05-14
Last Modified: 2010-04-23
Hello Experts,

1) I return a single string variable from a database. This string is the same as one of hundreds of winform controls on the page:
  examples:   "Button19", "Button78",  "Button32", "TextBox95", "Label2", etc

2) I want to alter a property for the control that has the same name. For example, if the returned string is "Button78", then I'd like to alter a property for the System.Windows.Forms.Button control named Button78.

  example: Button78.BackColor = Color.Blue

Can anyone please provide a routine to accomplish this?  I'm having trouble referencing or pointing to the desired control.

I have built a graphical representation of all the servers, switches, etc. in our server room. Each port was drawn as a small button. When I click any port button, I want the mating port (I get this button's name from the SQL database) to change color. I'm also using GDI+ to draw a line representing the connecting Cat5e wire between the two ports.


Question by:LarryZ
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    What version VB.Net are you working with?

    Author Comment

    VS2005 Standard
    LVL 85

    Accepted Solution


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ctlToFind As String = "Button1"
            Dim matches() As Control = Me.Controls.Find(ctlToFind, True)
            If matches.Length > 0 Then
                Dim ctl As Control = matches(0)
                ctl.BackColor = Color.Red
            End If
        End Sub

    Author Comment

    Works great !  Thanks for the very speedy reply.  Now I can continue to code on a day when I actually have the time.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now