How to Disable Static Text? 
Author Message
 How to Disable Static Text?

Hello everyone,

I read a discussion in this newgroup from about a year ago concerning
the HIG issues and disabling static text controls. I don't want to start
that argument again but...

There simply should be an elegant way to grey out/disable static text.

I'm using static text controls to label some popup menus and edit
fields. I have a check box that enables/disables several controls all at
once...everything but the damn labels. Whatever anyone's argument to
this is, it simply looks stupid and wrong.

So, I resorted to:

if (enabling the controls) then
   editfield1.enabled = true
   editfield2.enabled = true
   popupmenu1.enabled = true
   statictext1.textcolor = hsv(0,0,0)
   statictext2.textcolor = hsv(0,0,0)
   statictext3.textcolor = hsv(0,0,0)
else
   editfield1.enabled = false
   editfield2.enabled = false
   popupmenu1.enabled = false
   statictext1.textcolor = hsv(0,0,0.6)
   statictext2.textcolor = hsv(0,0,0.6)
   statictext3.textcolor = hsv(0,0,0.6)
end

While this works, it's not very elegant. Besides, I'm guessing at the
color.

Is there a better way?

- I tried a read-only editfield, but you can't make the backgroud color
  transparent.
- I don't want to completely rewrite a canvas to do the same thing.
- I can't figure out a way to sub-class a static text to add the
  funcionality.

Sorry if I missed something obvious. Please email me directly, remove
the REMOVE.

Thanks

Ray



Thu, 23 Sep 2004 00:29:28 GMT  
 How to Disable Static Text?

Quote:

>- I can't figure out a way to sub-class a static text to add the
>  funcionality.

Here's one way:

1) Create a new class. Call it clsGrayableText or something. Set its
super to StaticText.

2) Open up your new class and give it a new method named Enable. It
should take a boolean as its parameter.

3) The code for Enable might look like this:

  Sub Enable(blnEnabled As Boolean)

    If blnEnabled Then
      Me.TextColor = hsv(0,0,0)
    Else
      Me.TextColor = hsv(0,0,0.5)
   End

  End Sub

4) Drag the class into your window, which creates a new instance of it.
Name it. Then your main code would look like this:

   editfield1.enabled = true
   editfield2.enabled = true
   popupmenu1.enabled = true
   statictext1.enable true
   statictext2.enable true
   statictext3.enable true

Note that you're calling a function with an argument, not setting a
property to a value, as you are with the others.

If you wanted to get fancy, you could have a private enabled property so
the GrayableText would know its own state. You would call a method to get
the value of it elsewhere.

And if you wanted to get *really* fancy, you could subclass the editfield
and popup menu to make a version that could hold a reference to a
GrayableText class. Then you could rig it so that when you
enabled/disabled the editfield (or popup) it would know to also
enable/disable its associated label.

 - Jeff



Thu, 23 Sep 2004 14:54:33 GMT  
 How to Disable Static Text?

Quote:
> And if you wanted to get *really* fancy, you could subclass the editfield
> and popup menu to make a version that could hold a reference to a
> GrayableText class. Then you could rig it so that when you
> enabled/disabled the editfield (or popup) it would know to also
> enable/disable its associated label.
>  - Jeff

And you may want to save the text color before changing the color to
the disable color and when it's reenabled  I have a class like that
which i use all the time.


Wed, 06 Oct 2004 22:49:24 GMT  
 How to Disable Static Text?


Quote:

>> And if you wanted to get *really* fancy, you could subclass the editfield
>> and popup menu to make a version that could hold a reference to a
>> GrayableText class. Then you could rig it so that when you
>> enabled/disabled the editfield (or popup) it would know to also
>> enable/disable its associated label.
>>  - Jeff

> And you may want to save the text color before changing the color to
> the disable color and when it's reenabled  I have a class like that
> which i use all the time.

http://www.macest.com/downloads/statictextextras.rb.sit

This will do exactly as you want.

Regards.
--------
Chris Willis



Thu, 07 Oct 2004 05:06:52 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Disabling static text?

2. Selecting text in disabled text widget?

3. BUG? text doesnt appear in disabled text widgets

4. Selecting text with text widget disabled?

5. Bevel Button and Static Text

6. About Static texts on the dark side...

7. static text in Windows 95

8. Number of digits in static text

9. Hiding checkbox control with static text

10. Static text

11. Hiding and Showing Static Text

12. static text control

 

 
Powered by phpBB® Forum Software