简体   繁体   English

使用C#的GUI问题

[英]a problem with GUI using C#

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; button.Enabled = false;

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

// user clicked on button //用户点击了按钮

// do button's function //执行按钮的功能

button.Enabled= false; 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 ? 那为什么是这种颜色呢?

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. 这应该像单击之前一样恢复按钮的状态,基本上只是在进行处理时将其禁用。

The disabled state for most winform controls is largely fixed by the Win32 control set. 大多数Winform控件的禁用状态在很大程度上由Win32控件集固定。 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 使用WPF,它具有完全独立的实现,并且不受Win32根的影响
  • write your own button control from scratch (don't touch the Win32 one) 从头开始编写自己的按钮控件(不要触摸Win32)
  • use a 3rd-party button control 使用第三方按钮控件

禁用按钮后更改颜色

I had a similar issues with TextBox's before. 我之前在TextBox上也遇到过类似的问题。 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 http://blogs.msdn.com/jaredpar/archive/2007/02/12/readonly-textbox-that-doesn-t-look-funny.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM