How to create an event, when mouse reaches a certain area of the application

Asked

Viewed 501 times

1

I am developing an application in Delphi xe5 and would like to make a menu open to the mouse "enter" in an area of my form.

It’s kind of complicated to explain, but I’ll try to ... The windows taskbar has this option, it is hidden and when you arrive with the mouse where it is (usually below) the bar appears.

I would like to know how I can implement this in Delhi.

1 answer

1


One simple way to do it is to deal with the onMouseMove event

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
  HEIGHT_TITULO_JANELA = 50;
begin
  pnl1.Visible :=  (Y > (Height - pnl1.Height) - HEIGHT_TITULO_JANELA);

end;

if you want to control the display on the side instead of the Bottom, simply:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  pnl1.Visible :=  (X < pn1.Width); // para a esquerda
  pnl2.Visible :=  (X > (Width - pnl2.Width)); // para a direita
end;
  • Using this precedent, when initializing my form, the panel is already visible, and when losing the "focus" the idea was to make it hidden.

  • seven his Visible property for false in designTime or Form Create

  • Is already set to Visible false.

  • when it starts it is invisible, because the victim is false. If you approach it is visible. Now you want when the window loses focus it goes away too? That’s it?

  • Thanks to your idea, I was able to reach the following solution: if (Panelmenu.Visible=false) and (Mouse.CursorPos.X < Panelmenu.Width) then Panelmenu.Visible := true Else Panelmenu.Visible := false;

  • 1

    the panel is on the side? Then just change it. You just don’t need the IF. PanelMenu.Visible := (Mouse.CursorPos.X < PanelMenu.Width)

  • Exactly, the idea is to make an application similar to the Design of Windows 8, with a side menu

  • I added the examples to lateral.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.