Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:58:54+00:00 2026-05-13T05:58:54+00:00

I don’t get it. If I want to change the text on a button

  • 0

I don’t get it. If I want to change the text on a button from a thread other than the UI thread in Visual Basic .NET, I need to use a delegate, and do something along the lines of

 Private Delegate Sub SetTextDelegate(ByVal TheText As String)
 Private Sub delSetText(ByVal TheText As String)
     Button1.Text = TheText
 End Sub

 Private Sub ChangeText(ByVal TheText As String)
     If Button1.InvokeRequired Then
         Me.BeginInvoke(New SetTextDelegate(AddressOf delSetText), TheText)
     Else
         delSetText(TheText)
     End If
 End Sub

Of course I can make more generic functions that aren’t so hard-wired. But still, it seems like a lot of typing. Am I doing this in a roundabout way? How is this not included in the control properties—why would anyone leave this up to the programmer if it is required?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:58:54+00:00Added an answer on May 13, 2026 at 5:58 am

    In C#, anonymous methods are very helpful here; perhaps there is something similar in VB? (my VB-fu is weak). You might also re-use the current method rather than have two; as an example:

    void ChangeText(string text) {
        if(InvokeRequired) {
            this.Invoke((MethodInvoker) delegate {ChangeText(text);});
        } else {
            Button1.Text = text;
        }
    }
    

    Note that I’ve used MethodInvoker here deliberately – this is handled as a special case by Invoke, meaning it doesn’t have to use the (very slow) DynamicInvoke.

    I could also have done the .Text = text in the anon method, but that seems to violate DRY.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know where else to ask, but from one day to the other my
Don't get me wrong, I want them to get saved. But I always thought
Don't ask me why but I need to do the following: string ClassName =
I don't want to know a way to preload images, I found much on
For some reason, after submitting a string like this Jack’s Spindle from a text
Don't know if I worded the question right, but basically what I want to
Don't know how to explain it better but i'm trying to get a response
Don't be frightened, its a very basic code. Just wanted to check with you
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't these two mean the same thing, first get the value and then increment?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.