Its the little things that really annoy me

  • Thread starter Thread starter Steve Le Monnier
  • Start date Start date
S

Steve Le Monnier

Is there any quick way of fixing combo boxes or radio buttons so that on an
enquiry screen its possible to read their contents. As they don't have
read-only properties the only method available is to use the enabled
property, but this given an almost unreadable GUI.

In the VB days we used to dock troublesome controls onto frames and then
lock the frames but this is not an option anymore. Does anybody have an
alternative tip.

Its these kind of silly things that really frustrates and wastes a huge
amount of time.

Any suggestions gratefully received

Steve
 
Steve said:
Is there any quick way of fixing combo boxes or radio buttons so that
on an enquiry screen its possible to read their contents. As they
don't have read-only properties the only method available is to use
the enabled property, but this given an almost unreadable GUI.

In the VB days we used to dock troublesome controls onto frames and
then lock the frames but this is not an option anymore. Does anybody
have an alternative tip.

Its these kind of silly things that really frustrates and wastes a
huge amount of time.

Any suggestions gratefully received

Steve

When a container control has its enabled property set to false, all its
contained controls are disabled, as well. For example, if the user clicks on
any of the controls contained in a disabled GroupBox control, no events are
raised.
 
I agree Steve, I have just spent an hour trying to make a checkbox both
"display only" only to look in the discussions and find that it seems that it
will be yet another simple thing that is difficult to do.

Before anyone replys with "disabled controls should be greyed so the user
doesn't get confused about why they can't change them"... please give some
thought to users who don't want to go blind trying to see the status of
checkboxes etc. on a web form that is solely for enquiry. As my users are not
morons, they can deal with "display only" controls being readable and in any
colour they choose.

Please someone provide a usefull response to this.

Cheers,
Jamie/James
 
It is not a huge deal to create a read-only checkbox. I just did it for a
VB project. Below is an off-the-cuff (untested) C# version. The basic idea
is to cancel the effect of the CheckChanged event when ReadOnly = true. I
have also set the text associated with the checkbox to a slightly greyed
color so that it's still somewhat distinguishable from a non read-only
checkbox, yet still quite readable. You could add a DisabledForeColor
property if you wanted to make that more configurable.

I haven't bothered to put in design-time checks, so this version will refuse
to let you change the Checked property in the designer unless ReadOnly =
false.

Compile this as part of a separate library and add that library to your
designer controls toolbar.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace DevLib.Win.Controls {
class ReadOnlyCheckBox: CheckBox {

protected Color savedForeColor;
protected bool readOnly = false;
protected bool checkChangeFlag = false;
protected bool saveForeColorChangeFlag = true;

public ReadOnlyCheckBox() : base() {
this.savedForeColor = this.ForeColor;
}

public override Color ForeColor {
get {return base.ForeColor;}

set {
base.ForeColor = value;

if (this.saveForeColorChangeFlag == true) {
this.savedForeColor = value;
}

}

}

public virtual bool ReadOnly {
get {return this.readOnly;}

set {
this.readOnly = value;
this.saveForeColorChangeFlag = false;

if (value == true) {

if (this.savedForeColor == Color.DarkSlateGray) {
this.ForeColor = Color.DarkGray;
} else {
this.ForeColor = Color.DarkSlateGray;
}

} else {
this.ForeColor = this.savedForeColor;
}

}

}

private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{

if (this.readOnly == true) {
// Undo the change, making the control effectively read-only.
this.checkChangeFlag = true;
this.Checked = !this.Checked;
this.checkChangeFlag = false;
}

}

}

}
 
... You could add a DisabledForeColor property if you wanted to make that
more configurable.

Actually I meant "a DisabledReadOnlyColor".

The VB version has a Handles clause in the CheckChanged handler declaration;
I believe this event will need to be manually wired up in the
ReadOnlyTextBox constructor.

--Bob
 
Thank you Bob, I will try your suggestion. I looked for a simple (attribute
setting) way to solve the problem first and then went to the discussion group
when I realised that it was another "simple" thing that was going to take
more time than I allocated. When I saw the number of responses to similar
problems which took the approach of "well never mind what the customer wants,
the platform dictates that it should be something else" implying that most
users are morons (who can't understand why they can't change someting on a
page) and/or developers/architects are incabable of making wise decisions on
UI design/behaviour. It is a bit like saying that users should not be able to
choose their fore and back colours because they may pick the same colour for
each and then wonder why they can't see anything.

Thank you again very much for spending so much time to assist me. Your
attitude is obviously much better than the responses that others have
submitted to similar questions.

Cheers, J
 
Back
Top