开发者

Delphi Application.HintColor

In Delphi 2010 (don't know about other versions) Application.HintColor seems to have no effect when running on开发者_开发百科 Windows 7. On XP it gives the desired color. Any workarounds for this?


HintColor is like some of the other *Color properties in the VCL in that if you are running a themed application on a themed OS, they may be ignored when painting the control. Hints are a little different, because for them it's Vista or above, not XP or above. You can see this if you look at THintWindow.Paint in Controls.pas - it specifically paints the Vista gradient background if it's Vista and if themes are enabled.

This is normally a good thing, because you want your application to fit the look-and-feel of the OS and the user's preferences.

If you really want to override this, you will need to:

  • Subclass THintWindow
  • Get your application to use this new hint class when showing hints
  • In this class, override the painting methods to draw as you wish

Create a new hint class descending from THintWindow somewhere (more on what to implement below.) To get the application to use your new class for hints, assign an event handler to TApplication.OnShowHint (the easiest way to do this is via a TApplicationEvents component on your main form) and change the HintInfo parameter's HintWindowClass field to be your new class.

In your new hint class, you will need to override Paint and NCPaint. NCPaint will paint the border, and you will want to paint a non-themed border (probably using DrawEdge.) Change Paint to fill in the background with your colour of choice, and then draw text using DrawText in the hint's rectangle with appropriate text wrapping and alignment flags. If you look at the VCL code closely you can see a couple of rectangle offsets hardcoded, and you probably want to mimic these to get the same rectangles in your code as the VCL uses.

You can make all sorts of interesting variations of hints using this technique. One I made recently changed the painting so it drew a bold caption and then had other information under that, for example.

Finally: why are you setting the colour? Is it to warn the user of something or provide some other feedback? If so, consider using more than the colour - you can change anything you want about a hint using this technique. Try painting a warning icon or using rich-formatted text instead. I'd recommend you try to keep to the general theme look, and code tweaks to the themed painting, not overriding it entirely, because unless there's a very good reason you should try to keep to the OS / look the user has chosen.


No, not directly. If you have the runtime themes enabled it will take the system color for the hint. (IOW, the hint will be 'themed'). It is like setting a color for a button with the themes enabled (given that you can do this).

However you can use other 'hint' engines. For example you can use TjvBallonHint and/or TjvDesktopAlert (perhaps in conjunction with TjvDesktopAlertStack) from JEDI's JVCL which is free. There are also other (free & paid) alternatives. Also, if you want you can implement your own hint window.

HTH


Turning the 'enable runtime themes' off makes it work.


In Delphi 2010, you have TCustomHint class. You can derive a new class from it which draws a new type of hint.

You can assign your new class to CustomHint property of your forms or any other controls, and Delphi will use your custom hint class for showing hint for that control.

You can check source code of TBalloonHint class which is a sample TCustomHint descendant in Controls.pas

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜