Mega Code Archive

 
Categories / Delphi / Examples
 

Panel dependent TStatusbar.OnDblClick

Title: Panel dependent TStatusbar.OnDblClick Question: How can I tell which panel was clicked within a TStatusbar? Answer: The TStatusbar haven't got any event for telling which Panel the mouse was clicked in. To get this information you can use the following code. What is does: 1. It gets the current mouse coords 2. Loops trough all the panels testing if the mouse is inside the panel rect using the SB_GETRECT message to get the rect. //================================================================= procedure TMainForm.StatusBar1DblClick(Sender: TObject); var MouseCor : TPoint; PanelRect: TRect; lp0 : integer; SB : TStatusBar; begin if Assigned(sender) then begin if Sender is TStatusBar then begin GetCursorPos(MouseCor); SB := TStatusBar(Sender); for lp0 := 0 to SB.Panels.Count-1 do begin SendMessage(SB.Handle, SB_GETRECT, lp0, Integer(@PanelRect)); if PtInRect(PanelRect,SB.ScreenToClient(MouseCor)) then begin // Put code in here // SB.Panels[lp0] was clicked break; end; end; end; end; end; //=================================================================