Understanding how to have a different icon for each button state.

The SRP Button Control allows developers to set an icon for each button state, but the mechanism for doing so is not obvious when just looking at the property names. In understand how the icons are establish, we must first understand the concept of image frames.

Image Frames

Both the Icon and IconList properties allow you to establish a frame count. The frame count is used to determine how the loaded image file is divided into a list of smaller images, or frames. The easiest way to see this is by example. Here is a single image file, 288 pixels wide and 27 pixels tall.



This image clearly has nine icons in it, but the SRP Button Control doesn't know that. So, we set the frame count to 9. In so doing, the SRP Button Control divides the width of the whole image by 9 and those are the frame. In this case, setting the frame count to 9 results in 9 32-pixel wide images.

The frame count is set within the Icon and IconList properties, usually as a field or subvalue. For example, to load our sample image, we use this code:

Set_Property(@Window:".OLE_BUTTON", "OLE.Icon", "C:\myicons.bmp":@FM:9)

When we view the button, we see only the first of the nine icons on the button face:



Here's what happens when we load the sample image but forget to set the frame count to 9:


The entire 288 pixel wide image is centered on the button. Now the we understand how icons are divided, let's explore how the frames are used by the button.

Icon States

The SRP Button Control has up to nine states, so you can supply up to nine frames in your image:



The table below shows which frame applies to each state:

FrameState
1Normal
2Pressed
3Disabled
4Pressed when transitioning to Toggle/Tristate states
5Normal with Focus
6Pressed with Focus
7Hot (Mouse hovering over button during Normal state)
8Tristate (Button is in indetermined state)
9Tristate with Focus

The SRP Button Control has a hard-coded cascade algorithm for determining which image frames are used for which states of the controls. A cascade algorithm looks for a resource, and if not found, cascades to a more global resource, and so on until the desired resource is found or the top most resource is reached. In our case, the button will look for the image frame ideal for the current state, and if not found, will look to another suitable frame. If all else fails, the first frame is always used.

In short, you may include as many or as few frames as you wish and the SRP Button Control is smart enough to adapt.

See Also

IconIconList

  • No labels