Monday, May 21, 2012

A small Listbox appearance trick!

Another question has been raised by a foxite member inside the forum about a listbox not looking totally disabled when Enabled=.F. is set.  While the items in the listbox becomes disabled, the background color remains to be white.  And really it do not look cool that the rest of the other objects in a form like a textbox, when disabled changes color, while a listbox still remains white.

I have not seen this because I almost don't use Listboxes in favor of Grids. However, for those of you who may be wondering how this attitude can be circumnavigated, the trick lies between two properties:

a.  DisabledBackColor
b.  ItemBackColor

By default, listbox's DisabledBackColor is white while other objects have Rgb(236,233,216).  So change the listbox's DisabledBackcolor into that as well.  While this fixes the problem of items inside the listbox, when listbox is not full to the bottom, the empty space (no items) remains white.  That is because that empty space is not working under DisabledBackColor but under ItemBackColor property.  So the trick is to conditionally change it as well. 

Here is a sample form for that:

Local oForm

oForm = Createobject("Form1")
oForm.Visible = .T.
Read Events

Define Class Form1 As Form
    Top = 1
    Left = 0
    Height = 300
    Width = 287
    AutoCenter = .T.

    Add Object list1 As ListBox With ;
        Height = 160, ;
        Left = 12, ;
        Top = 48, ;
        Width = 264, ;
        Name = "List1",;
        DisabledBackColor = Rgb(236,233,216)

    Add Object command1 As CommandButton With ;
        top = 220,;
        left = 12,;
        Height = 40,;
        caption = 'Toggle'

    Procedure list1.Init

    Procedure command1.Click
        Thisform.list1.Enabled = !Thisform.list1.Enabled
        Thisform.list1.ItemBackColor = Iif(Thisform.list1.Enabled,Rgb(255,255,255),Rgb(236,233,216))

    Procedure Destroy
        Clear Events

No comments:

Post a Comment