Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No way to show a disabled checkbox caption as enabled?

Status
Not open for further replies.

mpgalvin

Programmer
Feb 5, 2001
119
IE
I have a checkbox and I want the caption to appear enabled when the box is disabled. Yeah, it's crap, but we have all labels enabled at all times, so a disabled checkbox caption looks bad beside it.

According to a thread here and some stuff at Wike, setting ForeColor to 0,0,1 and DisabledForeColor to 0,0,0 should do it. Apparently. While the caption is indeed "black" when disabled, I still have a very light shadow behind it. Is there no way of removing that entirely?

Failing that, I guess I need a composite VCX of checkbox plus my own label class (which looks enabled all the time) - but how would I go about recreating the focus rectangle going around the 'label' when the whole thing has focus (ie, work the same as a standard checkbox).

I'd like to avoid OLE controls if possible.
 
mpgalvin

You could probably get near your requirements with two shapes.

Shape1 would be transparent and borderless, shape2 would be transparent with a borderstyle = 5, ie dots.

By placing shape1 over the complete checkbox, you can disable it by obscuring it.

If you tab to the checkbox or click on shape1, you could make shape2 visible when the control has focus, thus simulating the default behaviour.

Needs playing with to fine tune the idea

Chris :)
 
Hi Mpgalvin,

When it comes to checkBox, the purpose of diabling is to avoid user to click on that. So let us think the otherway..
Instead of disabling the CheckBox... put the code

CheckBox.WhenEvent
******************
RETURN ThisForm.myCheckBoxEnabled

where myCheckBoxEnabled is a form level property and the value is set to .t. or. .f. as you desire. And whenever you decide to enable or diable the checkbox, put the code to change this property to .t. or .f.
The purpose is achieved.

Hope this helps you :)
ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
ramani, if I understand your code correctly, you're suggesting never physically disabling the checkbox, but just disabling access to it through a form property?

Chris, like your idea. Don't suppose you have such a control lying around, do you? :)
 
Some changes from the original post but basically the same idea

Create a new form with Format = Snap to Grid and add a single enabled checkbox with caption to be whatever your application requires.

Add Shape1, .Height = THISFORM.Check1.Height, .BackStyle = 0, .BorderStyle = 3.

Place Shape1 over Check1, run form and adjust until Shape1 covers the caption of Check1.

Add Shape2, .BackStyle = 0, .BorderStyle = 1.

Place Shape2 over Check1, run form and adjust until Shape2 covers the whole of Check1

Change Shape1.Visible = .F.
Change Shape2.BorderStyle = 0

In the .GotFocus event of Check1 put :-

THISFORM.Shape1.Visible = .T.

In the .LostFocus event of Check1 put :-

THISFORM.Shape1.Visible = .F.

In the .MouseMove event of Shape2 put :-

THISFORM.Shape1.Visible = .T.

In the .MouseMove event of THISFORM put :-

THISFORM.Shape1.Visible = .F.

You can then conditionally use the .Click event of Shape1 should you need to access Check1, by putting :-

IF lCondition
[tab]THISFORM.Check1.Click()
ENDI

HTH

Chris :)
 
Thanks Chris. I'm not sure why I need to show the "focus" shape when my mouse passes over it - normal checkboxes don't behave like that! Maybe in XP, huh?
 
Yes mpGalvin. Wgat I meant is ...

1. Create a form level property myCheckBoxEnabled
and put its value as .f. or .t. initialy.

2. Put in the checkBox.WhenEvent
Return ThisForm.myCheckBoxEnabled

3. Whenever you want to disable the checkbox, put the code..
ThisForm.myCheckBoxEnabled = .f.
and when you want to enable the code
ThisForm.myCheckBoxEnabled = .f.

:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Thanks ramani. Unfortunately, I've inherited this project and it has this bunch of classes pre-defined that work a certain way with the objects on the form. Throwing a brand new form property into the mix might just cause it to explode ;-)

 
mpgalvin

Showing the shape as the mouse passes over the control is just to simulate the control having focus.

If it's not important, leave it out - what may be more important is the ability to access the checkbox's PEMs through the click event of the shape, and if you were going to run with something like this, I would retain that feature.

Chris:)
 
I should know what PEMs are, but I don't. Little help?

So far, all I did was pretty much as the instructions, apart from the shape over the entire checkbox, and the conditional click on that shape

Basically, the control gets focus, I show the 'focus rectangle', it loses focus, I hide it. Nothing else has changed. Pretty simplistic, and frankly I'm waiting for the other shoe to drop and find that I've lost half the functionality.
 
mpgalvin

I have a checkbox and I want the caption to appear enabled when the box is disabled.

That was the original question - your last post indicates, unless I have misunderstood it, a doubt about its resolution?

Chris :)
 
Chris, I'm happy with what I have, but you know how it is with development. Something works fine on your computer when you're using it properly. Give it to a customer and they manage to break it within seconds. I can't find anything wrong with the checkbox as it is, but I'm concerned that you think I need a shape covering the entire control and accessing the checkbox's PEM through that shape - I'm not sure why.

It's probably too much info to go through here, I guess.
 
Idon't know if anyone else suggested this...
goto the properties of the chkbox and make it read only.
the apperance of the caption doesn't change and you are not able to select it. Prety simple and mabe do the trick for you.

d:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top