How Can I Implement Highlighted Toolbar Icons With Delphi?

后端 未结 3 1986
花落未央
花落未央 2021-02-10 12:29

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:55

    One can also use an ordinary TToolBar, with DrawingStyle set to dsGradient, I just found out.

    Sample toolbar with dsGradient as DrawingStyle

    0 讨论(0)
  • 2021-02-10 13:05

    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.

    0 讨论(0)
  • 2021-02-10 13:14

    Add a TActionManager to the form, and create some actions (e.g., bold, italic, and underline). Make sure to set the AutoCheck property to true for each action. Then add a TActionToolbar. Double-click the action manager, and drag the three actions to the toolbar. Now add a TXPColorMap to the form, and assign it to the action manager. Also add a TImageList and add icons for bold, italic, and underline (from C:\Program Files (x86)\Common Files\CodeGear Shared\Images\GlyFX\Icons\BMP\16x16). Assign the image list to the action manager.

    Set the toolbar icons to show only the glyph and not the caption. Finally, set the ActionManager's Style property to XP Style. The end result is what you seek.

    Toolbar sample

    0 讨论(0)
提交回复
热议问题