tags:

views:

315

answers:

4

Dear all at the begining of my application i disable some buttons and according to some conditions these buttons became enabled. my problem is when the user clicks on a button then it does my action its color becomes gray and that when i make it disabled again. for more explanation:

button.Enabled = false;

if(Condition) { button.enabled =true; }

// user clicked on button

// do button's function

button.Enabled= false; // here the button's color becomes gray and i dont want this attitude i want to be enabled where at the begining of the application when all buttons are disabled its color is qiut simmilar to button's background. So why this color ?

A: 

Change the color after disabling the button

ggf31416
A: 

I am not entirely sure I read your problem correctly, but It seems to me like maybe you want something like this:

button.Enabled = Condition; // Initial value


// user clicked on button
button.Enabled= false; 
 ... do button's function ...
button.Enabled = Condition

This should restore the state of the button as before the click, basically just disabling it while processing is taking place.

krosenvold
+1  A: 

The disabled state for most winform controls is largely fixed by the Win32 control set. If you don't like it, then either:

  • don't actually disable it - just change the color manually, disable tab-stops, and ignore clicks while it is "kinda-disabled"
  • use WPF, which has a completely separate implementation and doesn't suffer from the Win32 roots
  • write your own button control from scratch (don't touch the Win32 one)
  • use a 3rd-party button control
Marc Gravell
Do you need to write a button from scratch? It isn't too much work to inherit from the system Button class to customise the render behaviour. I wish it was easier for a disabled control to still display a tooltip to explain why it's disabled.
Jonathan Webb
A: 

I had a similar issues with TextBox's before. The best way to avoid this problem is to just reset the color after disabling the Button.

var color = button.BackgroundColor;
button.Enabled = false;
button.BackgroundColor = color;

http://blogs.msdn.com/jaredpar/archive/2007/02/12/readonly-textbox-that-doesn-t-look-funny.aspx

JaredPar