Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/plugins/qtranslate-x/qtranslate_frontend.php on line 497

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/themes/suffusion/functions/media.php on line 666

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/themes/suffusion/functions/media.php on line 671

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/themes/suffusion/functions/media.php on line 684

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/themes/suffusion/functions/media.php on line 689

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/vhosts/cadetill.com/domains/cadetill.com/public_html/wp-content/themes/suffusion/functions/media.php on line 694
VCL – El blog de cadetill
sep 302010
 

Buenas,

En los eventos de ratón de un TStatusBar solemos encontrar las coordenadas X, Y en la que se produce la acción, pero no así el panel, el cual puede ser interesante saber si queremos realizar una acción determinada según el panel (mostrar un hint dependiendo del panel, un menú contextual,…). La siguiente función nos devolverá dicho panel del TStatusBar.

function GetStatusBarPanelXY(StatusBar: TStatusBar; X, Y: Integer) : Integer;
var
  i: Integer;
  R: TRect;
begin
  Result := -1;

  // Buscamos panel a panel hasta encontrar en cual está XY
  with StatusBar do
    for i := 0 to Panels.Count - 1 do
    begin
      // Obtenemos las dimensiones del panel
      SendMessage(Handle, WM_USER + 10, i, Integer(@R));
      if PtInRect(R, Point(x,y)) then
      begin
        Result := i;
        Break;
      end;
    end;
end;

Los eventos del ratón que tienen coordenadas y con los que nos servirá la función son los siguientes:

  • OnMouseActivate
  • OnMouseDown
  • OnMouseMove
  • OnMouseUp
  • OnEndDrag
  • OnEndDock
  • OnDragOver
  • OnDragDrop
  • OnContextPopup (no tiene X e Y, pero tiene un TPoint que para el caso es lo mismo)

Espero que os sirva.

Nos leemos