StatusBar - saber qual panel clicou |
Top Previous Next |
|
unit Unit1;
interface
uses Forms, CommCtrl, Controls, StdCtrls, Classes, ComCtrls, Windows;
type TForm1 = class(TForm) StatusBar1: TStatusBar; Label1: TLabel; procedure StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure StatusBar1Click(Sender: TObject); private FX, FY: Integer; end;
var Form1: TForm1;
implementation
{$R *.dfm}
// o segredo é esta função function FindPanelAtPos(S: TStatusBar; X, Y: Integer): Integer; var I : Integer; PanelRect: TRect; Pt : TPoint; begin Result := -1; Pt.X := X; Pt.Y := Y; for I := 0 to S.Panels.Count-1 do if (SendMessage(S.Handle, SB_GETRECT, I, Integer(@PanelRect)) <> 0) and PtInRect(PanelRect, Pt) then begin Result := I; Break; end; end;
// quando clica no status bar exibe num label o caption do panel clicado procedure TForm1.StatusBar1Click(Sender: TObject); var Id: Integer; begin Id := FindPanelAtPos(StatusBar1, FX, FY); if Id > -1 then Label1.Caption := StatusBar1.Panels[Id].Text; end;
// captura posição do mouse ao mover sobre o statusbar procedure TForm1.StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin FX := X; FY := Y; end;
end. |