Click here to Skip to main content
13,046,087 members (51,855 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi , i have a button in my winForm ,, and it has a name and tag !
i want to find it and disable it!
how can i do it ?
Posted 17-Feb-13 4:02am
Sandeep Mewara 17-Feb-13 10:16am
And what is the issue it?
Sergey Alexandrovich Kryukov 17-Feb-13 14:19pm
What do you mean "by name or tag", exactly? Why using tags? Please clarify.
Most likely, this is just a bad idea leading to unsupportable code. You can always use member names, not property "Name", which you should not rely upon.
source.compiler 17-Feb-13 15:47pm
is it winapp? or web?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Try this:
IEnumerable<Button> buttons = this.Controls.OfType<Button>();
foreach (Button b in buttons)
      if (b.Name == "name" || b.Tag == "tag")
          b.Enabled = false;

If you've also containers on your form, such as Panels, then you should use recursion to disable also some buttons on the panel.

Hope this helps.
_Maxxx_ 18-Feb-13 0:16am
Great answer given the OP's original question!
ProgramFOX 18-Feb-13 12:07pm
Thank you!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

of course it has a name..
Button someButton = new Button();
someButton.Enabled = false;
Sergey Alexandrovich Kryukov 17-Feb-13 14:17pm
I up-voted this answer with my 4. Your naming for the button was somewhat confusing, so I clarified the code sample a bit. Would you mind? I usually show such simple code samples this way, and they are always understood correctly.

The problem is that OP's "name or tag" is confusing... Your answer is just the idea, which should be enough.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100