Is the a way for a ClickHandler to work IF the control is Enabled = False
? Like for example to show a messagebox with the message "Unable to change this data".
Asked
Active
Viewed 1,938 times
1

janlindso
- 1,225
- 3
- 16
- 41
-
Windows Forms? ASP.Net Web Forms? WPF/Silverlight? – Dennis Traub May 08 '12 at 16:39
-
2Enabled = false means "disable the click event". Displaying a message box to tell the user what she already knows isn't typically useful, but you'd need to leave Enabled to true and somehow otherwise give an indication that clicking doesn't do anything useful. In general, do reserve a message box for "Eek! Something bad happened!" kind of messages. You don't want to wear the user out and get her in auto-click mode when you *do* have something important to tell. – Hans Passant May 08 '12 at 16:53
-
The control is a DataGridView, and it looks same both enabled and disabled. – janlindso May 08 '12 at 16:56
-
Perhaps you could change the background color or alter the look in some other way when you disable it. It would seem to me that something like that would be better than a message box. – Steven Doggart May 08 '12 at 16:59
-
1Look at the accepted answer's link in this so question http://stackoverflow.com/questions/10467878/hide-certain-buttons-based-on-certain-matches/10468576#10468576 – Mark Hall May 08 '12 at 17:04
-
Thanks Mark, good idea! I'll go for that! – janlindso May 08 '12 at 17:14
3 Answers
0
quickest way: cover it with a 0% opacity Panel with an OnClick handler, panel1.Width = btn1.Width, Height, Location.

Matt Richard
- 170
- 1
- 9

Luka Ramishvili
- 889
- 1
- 11
- 20
0
In many instances, such as text fields, consider making them readonly instead of disabled

GabParrot
- 41
- 4
0
I have successfully used a TableLayoutPanel
control to cover a disabled Button
. The TableLayoutPanel
appears to be transparent by default. Use the EnableChanged
event of the Button
to show / hide the TableLayoutPanel
. My tests indicate this should work for a DataGridView
as well.

PKanold
- 139
- 7