RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMouse Class

TMouse surfaces information about the mouse and specifies how the application responds to mouse messages.

Pascal
TMouse = class;
C++
class TMouse;

Use the global Mouse variable, which is a TMouse object, to get information about the mouse. 

TControl descendants surface several events that let you respond to actions users make with the mouse. Typically, the event handlers for these events provide most of the information about the mouse that you need and you do not need to use the global Mouse variable. Instead, use the Mouse variable to obtain similar information outside of a mouse-related event or to specify more global aspects of how your application responds to mouse messages, such as how much the user must move the mouse to start a drag operation.  

C++ Examples: 

 

/*
This example uses two check boxes, three edit boxes and
a timer component on a form.  When the application starts,
the check boxes get checked by the application depending on
whether a mouse is detected and whether
a wheel button is available. The first edit box displays
the number of lines that are scrolled each time the wheel button
is rotated. The other two edit boxes display the position
of the mouse cursor at each millisecond, using the timer component.
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  CheckBox1->Checked = Mouse->MousePresent;
  CheckBox2->Checked = Mouse->WheelPresent;
  Edit1->Text = IntToStr(Mouse->WheelScrollLines);
  Edit2->Text = IntToStr((int)Mouse->CursorPos.x);
  Edit3->Text = IntToStr((int)Mouse->CursorPos.y);
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  Edit2->Text = IntToStr((int)Mouse->CursorPos.x);
  Edit3->Text = IntToStr((int)Mouse->CursorPos.y);
}

 

Delphi Examples: 

{
This example uses two check boxes, three edit boxes and
a timer component on a form.  When the application starts,
the check boxes get checked by the application depending on
whether a mouse is detected and whether
a wheel button is available. The first edit box displays
the number of lines that are scrolled each time the wheel button
is rotated. The other two edit boxes display the position
of the mouse cursor at each millisecond, using the timer component.
}
procedure TForm1.FormCreate(Sender: TObject);
begin
  CheckBox1.Checked := Mouse.MousePresent;
  CheckBox2.Checked := Mouse.WheelPresent;
  Edit1.Text := IntToStr(Mouse.WheelScrollLines);
  Edit2.Text := IntToStr(Mouse.CursorPos.X);
  Edit3.Text := IntToStr(Mouse.CursorPos.Y);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Edit1.Text := IntToStr(Mouse.WheelScrollLines);
  Edit2.Text := IntToStr(Mouse.CursorPos.X);
  Edit3.Text := IntToStr(Mouse.CursorPos.Y);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!