Click here to Skip to main content
11,925,851 members (59,109 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
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 5: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
Web04 | 2.8.151126.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2015
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