How would you disable .net Winforms Controls without changing their appearance?

Say I have a control and I want it to not be edited.

Setting the Enabled property of the control to False will work, but the appearance of the control will change accordingly, as a rule, to hard to read black over gray font. When readability is still important, this is a real problem.

There are several obvious fixes for TextBox:

Textbox1.BackColor = Color.White; 

or

 Textbox1.ReadOnly= true; // instead of setting Enabled to false 

but unfortunately this will not work for each control (e.g. radio buttons)

Another solution is to enable the Enabled property and subscribe to this focus event (but this is not a very elegant solution)

  this.Textbox1.Enter += new System.EventHandler(this.Textbox1_Enter); private void Textbox1_Enter(object sender, EventArgs e) { Textbox1.FindForm().ActiveControl = null; } 

Have you seen other ways to solve this problem? (and I mean real solutions, of course, you can capture a screenshot and display a copy above the control ...: p)

+6
c # winforms
source share
4 answers

There is an argument that interfering with the standard behavior of Windows confuses the user, but aside I have seen this before, although more often in C ++. You can subclass management and process paint messages yourself. When the control is enabled, simply delegate the drawing to the base class. When the control is disabled, you can either let the base class draw itself, and then do some custom drawing on top, or you can just draw the whole thing yourself. I highly recommend the first of these options.

+3
source share

Some controls can be installed on ReadOnly, which do not allow them to be enabled, but cannot be changed. Perhaps this is what you are looking for.

This suggests that you are likely to be a world of resentment when your users start to get confused, because it looks like they should be able to edit controls, but they can't. There is a reason why they change their appearance - this is a message about the status of the system to the user. Worry about this, and they can end up very confused.

0
source share

If the control is disabled / read-only, it really should look like disabled / read-only. Otherwise, you will completely confuse the user.

There are very good reasons why Windows Controls behave the way they do, and you really want to stay compatible with other Windows interfaces. When someone uses a Windows application, they have certain expectations about how they should look and act.

If you deviate from these expectations, then most often the user will think that your software is a piece of junk.

0
source share

Usually Yes, I do not want to change the default behavior of Windows.

But I have a case where I disable many controls on a page, usually in less than a second, to avoid some cross-threading issues in a multi-threaded application. This causes serious flickering problems when the user skips, for example, treeview or listbox. Without changing their appearance in this case, this is desirable.

However, when the controls are disabled for other reasons, I want their appearance to reflect their on / off status.

Flashing on / off states when this is just an instant thing actually leads to a much more negative perception of the software more than suppressing a change in appearance for disabled controls to avoid flashing many parts of the form.

0
source share

All Articles