How to determine Windows Theme TColors

你离开我真会死。 提交于 2019-12-11 08:02:40

问题


I am emulating (to the degree possible) a TPopup Menu so it can float and users can drag it around.

To do this, it's on its own form, and uses TPanels acting as if they are clickable TMenuItems.

I'm using TPanels so I can change their color.

To get the colors right, how can I determine at runtime (in Delphi 2010) the current theme's colors for TMenuItem.Color and TMenuItem.Font.Color (assuming such properties existed).

TIA

Edit

I could use clBtnFace for the background, and clWindowText for the text color. But, I need to know the the theme colors for when the mouse is over a menu selection.


回答1:


I believe the popupmenu uses the colour in the clMenu constant. If you need the colour as an rgb value, use ColorToRgb(clMenu) to translate it. There's clMenuBar, clMenuText and clMenuHighlight constants too.




回答2:


Have a look at my answer to How can I get the color for a themed tabsheet - especially the edit.

The relevant constants can be found under Parts and States. Just search for "MENU" on that page.

Edit: There are tools to explore themes visually - see Windows Visual Themes: Gallery of Parts and States?. (Thanks to @TOndrej for bringing this up.)




回答3:


You can use the constants clMenu and clMenuText.

There are more windows colors defined in Graphics.pas



来源:https://stackoverflow.com/questions/6177889/how-to-determine-windows-theme-tcolors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!