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

  • Home
  • SEARCH
  • 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 957169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:39:28+00:00 2026-05-16T00:39:28+00:00

Without going into detail about what I’m trying to achieve, is it possible (and

  • 0

Without going into detail about what I’m trying to achieve, is it possible (and if so how) can I reference an object that I don’t know the name of?
For example I want to saything like:

someButton.Text = someButton.Name;

But on the right side I don’t want to state the object name. So what I’d really like to do is something like:

someButton.Text = currentButton.Name;
otherButton.Text = currentButton.Name;

Essentially I want to dynamically assign the control text at runtime depending on a bunch of other stuff. Hopefully if I can do this I can just put decision making in a single method and reuse this.

Update: (I’m using Windows Forms.)
I was hoping there was some way for the program to know what control I was talking about (the current one) a bit like the this reference. So I didn’t have to keep passing in the specific object, if I’m going to do that I could probably just pass the string through. I was hoping to paste the same line of code calling the method every time I wanted it. I suspect I’m just being lazy… and what I want to do is ridiculous.

And there’s no associated event for the control.

I reckon the answer might be to customise the controls. (Not just buttons, a variety of GUI controls). Which is going to take A LOT more effort than my alternative.

  • 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-16T00:39:29+00:00Added an answer on May 16, 2026 at 12:39 am

    How do you determine the “current” button?

    Was it just clicked? Use the sender argument to the Click event handler (and cast it to Button).

    Do you mean the one with focus? Read the ActiveControl property (and cast it to Button).

    EDIT: Wait, by current button you mean the one on the left hand side of the assignment statement? If you want to perform some operation of a bunch of different buttons you can definitely avoid naming each button multiple times. Here’s an example:

    foreach(Button currentButton in new Button[] { thisButton, thatButton, otherButton, yetAnotherButton })
    {
        currentButton.Text = currentButton.Name;
    }
    

    or

    Action<Button> copyName = (currentButton) => currentButton.Text = currentButton.Name;
    copyName(thisButton);
    copyName(thatButton);
    copyName(otherButton);
    copyName(yetAnotherButton);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LARGE datatable (500k-1m rows), without going into detail this is a
Without going into whether this is a good or bad idea: Is it possible
Without going into too much detail (I am looking for debugging techniques here), I
Without going into too much detail, I'm building a Django site and I wanted
Without going into the gory details I want to use a #define macro that
Without going into too much detail we are looking to use XML as meta-data
I am testing my new image file format, which without going into unnecessary detail
I'm going to outline my problem in detail to explain what I'm trying to
Problem: Without going into requirements I have clients applications on iPhone and Android which
Using any combination of Linux tools (without going into any full featured programming language)

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.