delphi statusbar控件(状态栏)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi statusbar控件(状态栏)相关的知识,希望对你有一定的参考价值。

状态栏有3个子栏目,怎么写出点击第3个子栏目里面的文字出现网页(只能时单击第3子栏目的文字才会出现效果,第一子栏目和第二单击没效果)

参考技术A //statusbar1单击事件

var
Pt: TPoint;
I,Idx,PC,W,H: Integer;
R: TRect;
S: string;
begin
//先粗略取坐标,看是点在哪个格子上的
GetCursorPos(Pt);
Pt := StatusBar1.ScreenToClient(Pt);
Idx := -1;
R := Rect(0,0,0,StatusBar1.Height);
PC := StatusBar1.Panels.Count - 1;
for I := 0 to PC do
begin
R.Left := R.Right;
if I = PC then
R.Right := StatusBar1.Width
else
R.Right := R.Left + StatusBar1.Panels[i].Width;
if PtInRect(R,Pt) then
begin
Idx := I;
Break;
end;
end;
if Idx = -1 then
Exit;
//现根据文字宽度,确定在否在文字上
S := StatusBar1.Panels[Idx].Text;
W := StatusBar1.Canvas.TextWidth(S);
H := StatusBar1.Canvas.TextHeight(S);
InflateRect(R,-1,0);
if W < R.Right - R.Left then
case StatusBar1.Panels[Idx].Alignment of
taLeftJustify: R.Right := R.Left + W;
taRightJustify: R.Left := R.Right - W;
taCenter: InflateRect(R,- (R.Right - R.Left - W) div 2,0);
end;
if H < R.Bottom - R.Top then
InflateRect(R,0,-(R.Bottom - R.Top - H) div 2);
if not PtInRect(R,Pt) then
Exit;
//这里idx就是点中文字格子索引,自己选择,打开网页,这里是将文字做为网址打开,你可以自己维护一个网址表
ShellExecute(Application.Handle, nil, PChar(S), nil, nil, SW_SHOWNORMAL);
end;

以上是关于delphi statusbar控件(状态栏)的主要内容,如果未能解决你的问题,请参考以下文章

ReactNative: 使用StatusBar状态栏

增强Delphi的TStatusBar控件

VB 状态栏动态显示时间

WPF,从用户控件中更新主窗口中的状态栏

Win32 状态栏用法

2021-08-24 WPF控件专题 StatusBar 控件详解