How Can I Implement Highlighted Toolbar Icons With Delphi?

后端 未结 3 1952
自闭症患者
自闭症患者 2021-02-10 12:25

I\'d like to highlight my toolbar icons when their associated action has it\'s \"checked\" property set to true. I\'d like to do it in a manner similar to how Microsoft Office 2

3条回答
  •  梦如初夏
    2021-02-10 12:56

    Without changing the entire theme, I think this is something that might work half decently:

    1. Add extra images to the ImageList, so that for a given action, there are two (or more) images to choose from.

    2. Instead of changing the "checked" property to true or false, change the ImageIndex to the alternative image, e.g.:

      if WS = 1 then begin
        ElTree.Align := alTop;
      //  TileTopBottomAction.Checked := true;  --- take this out
      //  TileLeftRightAction.Checked := false;  --- take this out
        TileTopBottomAction.ImageIndex := 47;  { hilighted image }
        TileLeftRightAction.ImageIndex := 14;  { regular image }
      end 
      else begin
        ElTree.Align := alLeft;
      //  TileTopBottomAction.Checked := false;  --- take this out
      //  TileLeftRightAction.Checked := true;  --- take this out
        TileTopBottomAction.ImageIndex := 13;  { regular image }
        TileLeftRightAction.ImageIndex := 48;  { hilighted image }
      end;
      

    Now the images will look like this on the toolbar:

    toolbar

    and like this on the menu:

    menu

    The nice things about this method is that it also works on the menu, and you can have multiple images to represent what you want. Also, it will not wreck the theme (XP, Vista, Windows 7, etc) that the program has taken on.

    The disadvantage of this method is: You are limited to 16x16 image area to play with and cannot draw a box around it that are outside those limits as happens when you set the "checked" property to true.

提交回复
热议问题