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

Posted on 2006-05-14
Medium Priority
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
  • 2
  • 2
LVL 86

Expert Comment

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

Author Comment

ID: 16677570
VS2005 Standard
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 16677575

    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

ID: 16677593
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

862 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