gpt4 book ai didi

delphi - 我想要更个性化的BalloonHint(背景颜色/圆角/透明度)

转载 作者:行者123 更新时间:2023-12-02 02:56:48 26 4
gpt4 key购买 nike

使用TballoonHint时,我需要它在颜色、形状、透明度和动画外观上更加个性化,我该怎么做?

最佳答案

创建您自己的 TBalloonHintTHintWindow 的后代。重写NCPaint方法来绘制外边缘(非客户区)和CalcHintRect(如果需要),并提供您自己的Paint方法按照您希望的外观绘制内部。

然后在调用 Application.Run 之前将其分配给 .dpr 文件中的 Application.HintWindowClass

这是一个(非常简单的)示例,除了用绿色背景绘制标准提示窗口之外什么也不做。

将其另存为MyHintWindow.pas:

unit MyHintWindow;

interface

uses
Windows, Controls;

type
TMyHintWindow=class(THintWindow)
protected
procedure Paint; override;
procedure NCPaint(DC: HDC); override;
public
function CalcHintRect(MaxWidth: Integer; const AHint: string; AData: Pointer): TRect;
override;
end;

implementation

uses
Graphics;

{ TMyHintWindow }

function TMyHintWindow.CalcHintRect(MaxWidth: Integer;
const AHint: string; AData: Pointer): TRect;
begin
// Does nothing but demonstrate overriding.
Result := inherited CalcHintRect(MaxWidth, AHint, AData);
// Change window size if needed, using Windows.InflateRect with Result here
end;

procedure TMyHintWindow.NCPaint(DC: HDC);
begin
// Does nothing but demonstrate overriding. Changes nothing.
// Replace drawing of non-client (edges, caption bar, etc.) with your own code
// here instead of calling inherited. This is where you would change shape
// of hint window
inherited NCPaint(DC);
end;

procedure TMyHintWindow.Paint;
begin
// Draw the interior of the window. This is where you would change inside color,
// draw icons or images or display animations. This code just changes the
// window background (which it probably shouldn't do here, but is for demo
// purposes only.
Canvas.Brush.Color := clGreen;
inherited;
end;

end.

使用它的示例项目:

  • 创建一个新的 VCL 表单应用程序。
  • 在对象检查器中将 Form1.ShowHint 属性设置为 True
  • 将任何控件(例如 TEdit)拖放到表单上,然后在其 Hint 属性中放置一些文本。
  • 使用项目->查看源代码菜单显示项目源代码。

将指示的行添加到项目源代码中:

program Project1;

uses
Forms,
MyHintWindow, // Add this line
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
HintWindowClass := TMyHintWindow; // Add this line
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

示例输出(丑陋,但有效):

Image of memo control with ugly green hint popup

关于delphi - 我想要更个性化的BalloonHint(背景颜色/圆角/透明度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20748641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com