Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

[VB6] ColorList - Another example of a custom dropdown list control

$
0
0
ColorList:

A "dropdown list box" control for choosing among a list of predefined colors.

This is a sort of drop-down list box written in VB6 that accepts a series of color text/value pairs. Users may choose a color via the mouse or keyboard.


Name:  sshot.png
Views: 117
Size:  11.5 KB

When too near the bottom of the screen the
list "drops up" instead of down.


Selection is by "pair" i.e. even though text "names" are displayed the name can't be typed in to choose.

Instead to make a choice via keyboard the user presses the spacebar to drop down the list, arrows up and down within the list, then types space or enter to select a text/value pair. The user can also type escape or tab to "cancel." Both actions "retract" the drop-down list.

By mouse the user can click the drop-down triangle symbol to drop the list, then scroll as necessary and click on an item to choose it. Clicking "away from" the dropdown list retracts it.

There is just one Event implemented: Click. This Click Event is raised when the user selects a new value, but not when the user cancels.

Properties Color and Text can then be fetched to obtain the choice.


Property Colors:

The color list is defined via the Colors Property, a String value. This is a list of "pairs" separated by pipe (|) characters. Each pair is a text name, a comma (,), and an 8-digit hex color value of OLE_COLOR type (i.e. system color values can be used).

Example:

"Blue,00FF0000|Green,0000FF00|Red,000000FF|Button Face,8000000F"

The text ("names") can be any text that doesn't contain a comma or a pipe.

Until Colors has a valid value assigned (design-time or run-time) the dropdown action does not occur.


Property Color:

This is a Long (OLE_COLOR) value. RGB colors are in "BGR" sequence as usual, and values with bit 31 set are OLE system color values.

The initial value may be assigned at design-time or run-time.

When this is assigned at design-time or programmatically, the Color is looked up in Colors and Text is assigned (if not found Text gets the UNKNOWN_COLOR_TEXT Const value).

The Colors Property should be assigned first.


Property Text:

This is a String value.

The initial value may be assigned at design-time or run-time.

When this is assigned at design-time or programmatically, the Text is looked up in Colors and Color is assigned (if not found Color gets the UNKNOWN_COLOR Const value).

The Colors Property should be assigned first.


Requirements:

VB6

32-bit Windows, or 64-bit Windows with WOW64 subsystem.

Only tested on Windows 10, but should work on Win9x all the way back to Windows 95.


Pieces and Parts:

ColorList.ctl
ColorList.ctx
ColorListPopup.frm
Subclasser.bas

Subclasser.bas can be removed along with calls to it and some exception handling code if you don't need ther "dropdown" to get retracted automatically when the application loses focus. See comments within ColorListPopup.frm for more details.


Remarks:

This seems to be working fine on Windows 10, but more testing is needed on downlevel versions of Windows.

In particular I'd be concerned about proper positioning of the popup/dropdown Form. It should be right under the ColorList instance (or if positioned low on the screen, right ABOVE the ColorList). "Fat" Aero borders might be a factor that could throw this off.

This UserControl might also serve as a model for creating other kinds of custom "dropdown list" controls.

ColorList (and supporting modules) compile down pretty small, adding much less size than any standard OCX we might use for this.
Attached Images
 

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>