Solved

I have: Name of a button, and I want to change the text of it

Posted on 2007-03-30
2
161 Views
Last Modified: 2010-04-23
I want to change the text of a button. What I know is the name of the button and the new text.

So I have tried this:

Private Sub me_text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles me_text.TextChanged
        GetControl(me_control.Text).Text = me_text.Text
    End Sub

    Private Function GetControl(ByVal _Name As String) As Button
        Dim entry As Control
        For Each entry In Controls                                     'searching all controls
            If entry.GetType.Name = "Button" Then            'only search for name if its a button
                If entry.Name = _Name Then                         'if the button has the name of the button that I want
                    Return entry                                              'return entry, which is a button
                End If
            End If
        Next
    End Function

What is wrong?

Thanks

Sven
0
Comment
Question by:Ruttensoft
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18822399
what error do you get?

maybe this works better:
 Private Function GetControl(ByVal _Name As String) As Button
        Dim entry As Control
        For Each entry In Controls                                     'searching all controls
            If entry.GetType.Name = "Button" Then            'only search for name if its a button
                If entry.Name = _Name Then                         'if the button has the name of the button that I want
                    Return entry as Button                                              'return entry, which is a button
                End If
            End If
        Next
    End Function
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 18822506
Hi Ruttensoft,

If you are using VS2005, you can use this....

     CType(Me.Controls.Find(me_control.Text, True)(0), Button).Text = me_text.Text

Else, you might like to take a look at this -> http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21564702.html

Regards,

Wayne
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expando 4 47
Get list of word ducuments in a folder 10 36
I need help exporting info from a dataset to Excel in my VB.Net application 7 50
Web Form VB.Net  import CSV 4 26
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now