How to set some functions when mouse is moving over form objects

How to set some functions when mouse is moving over form objects

How to set some functions when mouse is moving over form objects

How to set some functions when mouse is moving over form objects.

DownloadDownload This Tutorials

Bookmark:

How to set some functions when mouse is moving over form objects

This program demonstrates how to change form properties according to mouse movements. On this tutorial it changes the color of the rectangle and cursor shape as user move mouse over each rectangle on the form. Main goal of this tutorial is to demonstrate how to set some function when mouse is moving over form objects.

Take action while mouse moving around form objects

Following procedure set shape color into black and change the default shape cursor. You have to repeat this procedure for each shape. Here is only for one shape. It is similar for all the shape.

procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    If (CheckBox1.Checked) And  (Shape1.Brush.Color<>clBlack) Then
            Shape1.Brush.Color:=clBlack;
    If (CheckBox2.Checked) And (Shape1.Cursor<>crDrag) Then
            Shape1.Cursor:=crDrag;
end;

Use this procedure to set shape color and cursor shape to default.

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
Var 
	X1, X2, Y1, Y2 : Integer;
begin
    If Shape1.Brush.Color=clBlack Then
    Shape1.Brush.Color:=clWhite;
    If Shape2.Brush.Color=clBlack Then
    Shape2.Brush.Color:=clWhite;
    If Shape3.Brush.Color=clBlack Then
    Shape3.Brush.Color:=clWhite;
    If Shape4.Brush.Color=clBlack Then
    Shape4.Brush.Color:=clWhite;
    If Shape5.Brush.Color=clBlack Then
    Shape5.Brush.Color:=clWhite;
    If Shape6.Brush.Color=clBlack Then
    Shape6.Brush.Color:=clWhite;
    If Shape7.Brush.Color=clBlack Then
    Shape7.Brush.Color:=clWhite;
    If Shape1.Cursor<>crDefault Then
    Shape1.Cursor:=crDefault;
    If Shape2.Cursor<>crDefault Then
    Shape2.Cursor:=crDefault;
    If Shape3.Cursor<>crDefault Then
    Shape3.Cursor:=crDefault;
    If Shape4.Cursor<>crDefault Then
    Shape4.Cursor:=crDefault;
    If Shape5.Cursor<>crDefault Then
    Shape5.Cursor:=crDefault;
    If Shape6.Cursor<>crDefault Then
    Shape6.Cursor:=crDefault;
    If Shape7.Cursor<>crDefault Then
    Shape7.Cursor:=crDefault;
    Label1.Caption:='X : '+IntToStr(X)+' Y : '+IntToStr(Y);
end;

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - On-mousemove-over-objects.zipOn-mousemove-over-objects.zip
       File size: 5 KB, File type: zip
       Total downloads: 204, Upload date: February 10 - 2009

Leave a comment