• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

DoubleClick on a TStatusPanel

I need to have a OnDubleClick event on a TStatusPanel

(IE inside a statusBar OnDoubleClick I need to know which of the StatusPanels the double click is on
0
wqclatre
Asked:
wqclatre
1 Solution
 
mokuleCommented:
Maybe try like this

var
    xm,ym: integer;


procedure TForm1.StatusBar1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  xm := X;
  ym := Y;
end;

procedure TForm1.StatusBar1DblClick(Sender: TObject);
var
  i: integer;
  dx: integer;
begin
  dx := 0;
  for i := 0 to StatusBar1.Panels.Count - 1 do
    begin
    if (xm > dx) and (xm < dx+ StatusBar1.Panels[i].Width) then
      begin
      ShowMessage(IntToStr(i));
      exit;
      end;
    dx := dx + StatusBar1.Panels[i].Width;
    end;
  ShowMessage('No panel clicked');
end;
0
 
wqclatreAuthor Commented:
I don't like the idea of Global variables.

Isn't there a way to get the ScreenPositions for the StatusPanel[2] for example ?
0
 
mokuleCommented:
It's up to You how You declare xm, ym.
They can be private members in the Form's class.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
calinutzCommented:
Have you tryed this:

Statusbar2.ClientOrigin.X
Statusbar2.ClientOrigin.Y


Regards
0
 
wqclatreAuthor Commented:
Feels "global" to me.....  (global within the unit)
0
 
TheRealLokiSenior DeveloperCommented:
This is all you need, and is not global

procedure TForm1.StatusBar1DblClick(Sender: TObject);
var
  WhichPanel, wdth: integer;
  cp: tpoint;
begin
  cp := mouse.CursorPos;
  cp.x := cp.x - (sender as TStatusBar).ClientOrigin.x;
  WhichPanel := 0;
  wdth := 0;
  while (WhichPanel < (sender as TStatusBar).Panels.Count) and
        (cp.x > wdth + (sender as TStatusBar).Panels[WhichPanel].Width) do
  begin
    wdth := wdth + (sender as TStatusBar).Panels[WhichPanel].Width;
    inc(WhichPanel);
  end;
  ShowMessage('You clicked on panel # ' + Inttostr(WhichPanel));
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now