1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
unit Unit1;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TOnHintEvent = procedure(Sender: TObject; HintInfo: PHintInfo) of object;
TMyHintControl = class (TCustomControl)
private
FBlueRect, FRedRect, FWhiteRect, FYellowRect: TRect;
FOnHintEvent: TOnHintEvent;
FShowOnlyRed: Boolean;
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure SetOnHintEvent(const Value: TOnHintEvent);
procedure SetShowOnlyRed(const Value: Boolean);
protected
procedure Resize; override;
public
constructor Create(TheOwner: TComponent); override;
procedure Paint; override;
property ShowOnlyRed: Boolean read FShowOnlyRed write SetShowOnlyRed;
property OnHintEvent: TOnHintEvent read FOnHintEvent write SetOnHintEvent;
end;
TMyHintButton = class (TButton)
private
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
protected
public
end;
{ TForm1 }
TForm1 = class(TForm)
Button7: TButton;
Button8: TButton;
CheckBox1: TCheckBox;
ListBox1: TListBox;
ButtonClear: TButton;
GroupBoxNoShowHint: TGroupBox;
ButtonShowHintNoParent1: TButton;
Button1: TButton;
Button2: TButton;
ButtonNoShowHintShowParent: TButton;
GroupBoxShowHint: TGroupBox;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure CheckBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonClearClick(Sender: TObject);
private
{ Private declarations }
FMyHintControl,FMyHintControl2 : TMyHintControl;
FMyHintButton: TMyHintButton;
procedure HintEvent(Sender: TObject; HintInfo: PHintInfo);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TMyHintControl }
procedure TMyHintControl.CMHintShow(var Message: TMessage);
begin
with TCMHintShow(Message), HintInfo^ do
begin
if Assigned(FOnHintEvent) then
FOnHintEvent(Self, HintInfo);
Result := 1;
if PtInRect(FRedRect, CursorPos) then
begin
Result := 0;
HintStr := 'Red' + #13#10 + 'aaaaa_bbbbb_ccccc_dddddd_eeeeee';
CursorRect := FRedRect;
end;
if FShowOnlyRed then
Exit;
if PtInRect(FBlueRect, CursorPos) then
begin
Result := 0;
HintStr := 'Blue';
CursorRect := FBlueRect;
end;
if PtInRect(FYellowRect, CursorPos) then
begin
Result := 0;
HintStr := 'Yellow';
CursorRect := FYellowRect;
end;
if PtInRect(FWhiteRect, CursorPos) then
begin
Result := 0;
HintStr := 'White';
CursorRect := FWhiteRect;
end;
end;
end;
constructor TMyHintControl.Create(TheOwner: TComponent);
begin
inherited;
Hint := 'Control Hint';
ShowHint := True;
end;
procedure TMyHintControl.Paint;
begin
with Canvas do
begin
Brush.Color := clRed;
FillRect(FRedRect);
Brush.Color := clWhite;
FillRect(FWhiteRect);
Brush.Color := clBlue;
FillRect(FBlueRect);
Brush.Color := clYellow;
FillRect(FYellowRect);
end;
end;
procedure TMyHintButton.CMHintShow(var Message: TMessage);
begin
TCMHintShow(Message).HintInfo^.HintStr := 'CMHintShow';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FMyHintControl := TMyHintControl.Create(Self);
with FMyHintControl do
begin
ShowOnlyRed := True;
OnHintEvent := HintEvent;
Parent := Self;
SetBounds(10, 10, 100, 100);
Visible := True;
end;
FMyHintControl2 := TMyHintControl.Create(Self);
with FMyHintControl2 do
begin
OnHintEvent := HintEvent;
Parent := Self;
SetBounds(120, 10, 100, 100);
Visible := True;
end;
FMyHintButton := TMyHintButton.Create(Self);
FMyHintButton.Parent := GroupBoxShowHint;
FMyHintButton.Left := Button7.Left;
FMyHintButton.Width := Button7.Width;
FMyHintButton.Top := Button7.Top + 36;
FMyHintButton.ParentShowHint := True;
FMyHintButton.ShowHint := True;
FMyHintButton.Caption := 'ShowHint = True Parent = True / Hint = '''' / CMHintShow';
end;
procedure TForm1.CheckBox1Change(Sender: TObject);
begin
if CheckBox1.Checked then
begin
GroupBoxNoShowHint.Hint := '';
GroupBoxShowHint.Hint := '';
end
else
begin
GroupBoxNoShowHint.Hint := 'GroupBox';
GroupBoxShowHint.Hint := 'GroupBox';
end;
end;
procedure TMyHintControl.Resize;
begin
inherited;
FRedRect := Rect(0, 0, Width div 2, Height div 2);
FWhiteRect := Rect(Width div 2, 0, Width, Height div 2);
FBlueRect := Rect(0, Height div 2, Width div 2, Height);
FYellowRect := Rect(Width div 2, Height div 2, Width, Height);
end;
procedure TMyHintControl.SetOnHintEvent(const Value: TOnHintEvent);
begin
FOnHintEvent := Value;
end;
procedure TForm1.HintEvent(Sender: TObject; HintInfo: PHintInfo);
begin
with HintInfo^ do
begin
ListBox1.Items.Add(Format('CursorPoint X: %d Y: %d', [CursorPos.X, CursorPos.Y]));
ListBox1.Items.Add(Format('CursorRect L: %d T: %d R: %d B: %d',
[CursorRect.Left, CursorRect.Top, CursorRect.Right, CursorRect.Bottom]));
end;
end;
procedure TForm1.ButtonClearClick(Sender: TObject);
begin
ListBox1.Clear;
end;
procedure TMyHintControl.SetShowOnlyRed(const Value: Boolean);
begin
FShowOnlyRed := Value;
end;
end.
|