Difference between revisions of "Cursor"

From Lazarus wiki
Jump to navigationJump to search
(Cursor - property of the TCursor Object.)
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 62: Line 62:
 
(3) On the ComboBox1Change procedure add this code:
 
(3) On the ComboBox1Change procedure add this code:
  
<delphi>
+
<syntaxhighlight>
 
procedure TForm1.ComboBox1Change(Sender: TObject);
 
procedure TForm1.ComboBox1Change(Sender: TObject);
 
begin
 
begin
 
     Form1.Cursor := StringToCursor(ComboBox1.Text);
 
     Form1.Cursor := StringToCursor(ComboBox1.Text);
 
end;
 
end;
</delphi>
+
</syntaxhighlight>
  
 
This will allow you to select the cursor type from the ComboBox and see it when you move the mouse over the Form. Only when you hover over the ComboBox will the cursor return to the default (crDefault).
 
This will allow you to select the cursor type from the ComboBox and see it when you move the mouse over the Form. Only when you hover over the ComboBox will the cursor return to the default (crDefault).
Line 77: Line 77:
 
'''EXAMPLE 2: Change An Objects Cursor'''
 
'''EXAMPLE 2: Change An Objects Cursor'''
  
<delphi>
+
<syntaxhighlight>
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
begin
 
begin
Line 89: Line 89:
 
     // Changes the Memo1 cursor to an hour glass.
 
     // Changes the Memo1 cursor to an hour glass.
 
end;  
 
end;  
</delphi>
+
</syntaxhighlight>
  
  
Line 97: Line 97:
 
'''EXAMPLE 3: Change All Controls To An Hour Glass, Except TBitBtn Controls'''
 
'''EXAMPLE 3: Change All Controls To An Hour Glass, Except TBitBtn Controls'''
  
<delphi>
+
<syntaxhighlight>
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
var
 
var
Line 109: Line 109:
 
     end;
 
     end;
 
end;  
 
end;  
</delphi>
+
</syntaxhighlight>
  
 
However, if you had a GroupBox, you would have to address the controls within it separately.
 
However, if you had a GroupBox, you would have to address the controls within it separately.
  
<delphi>
+
<syntaxhighlight>
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
var
 
var
Line 130: Line 130:
 
     end;
 
     end;
 
end;   
 
end;   
</delphi>
+
</syntaxhighlight>
  
 
With the above example, in which you had Form1, as well as other controls on the form such as Memo1, Edit1, Image1, BitBtn, etc., this would change all but the BitBtn controls to the Hour Glass.  There are controls such as the TGroupBox, TPanel, that act as individual containers for controls, and these items must be addresses separately from the main Form in order to change their internal control set to a different cursor at runtime.
 
With the above example, in which you had Form1, as well as other controls on the form such as Memo1, Edit1, Image1, BitBtn, etc., this would change all but the BitBtn controls to the Hour Glass.  There are controls such as the TGroupBox, TPanel, that act as individual containers for controls, and these items must be addresses separately from the main Form in order to change their internal control set to a different cursor at runtime.

Revision as of 14:02, 24 March 2012

Cursor - property of the TCursor Object.


Cursor Constants

  • crAppStart <= Arrow with small hour glass in the lower right corner.
  • crArrow <= Arrow
  • crCross <= Cross
  • crDefault <= Same as Arrow.
  • crDrag <= Arrow with a dotted box going through the bottom part of the Arrow.
  • crHandPoint <= Hand with pointing index finger (same as you would see when hovering over a link in a browser).
  • crHelp <= Arrow with a question mark to the right of it.
  • crHourGlass <= Hour Glass
  • crHSplit <= Horizontal Split (A left arrow, two pipes in the center, and a right arrow.)
  • crIBeam <= IBeam
  • crMultiDrag <= Same as crDrag but there are two boxes going through the bottom part of the Arrow.
  • crNo <= A black circle with a slash through it.
  • crNoDrop <= A white circle with a slash through it.
  • crNone <= No cursor. The mouse pointer is invisible.
  • crSizeAll <= A cross with arrows on the tips.
  • crSizeNESW <= An animated, double arrow cursor that is joined, pointing from North East to South West.
  • crSizeNS <= An animated, double arrow cursor that is joined, pointing from North to South.
  • crSizeNWSE <= An animated, double arrow cursor that is joined, pointing from North West to South West.
  • crSizeWE <= An animated, double arrow cursor that is joined, pointing from West to East.
  • crSQLWait <= An hour glass with the letters SQL beneath it.
  • crUpArrow <= A black arrow pointing up.
  • crVSplit <= Vertical Split (A left arrow, two pipes in the center, and a right arrow.)




EXAMPLE 1: To View All The Cursor Types

(1) On Form1, drag a ComboBox control onto the Form.

(2) Set the ComboBox1, Items (TStrings) to the following:

crAppStart
crArrow
crCross
crDefault
crDrag
crHandPoint
crHelp
crHourGlass
crHSplit
crIBeam
crMultiDrag
crNo
crNoDrop
crNone
crSizeAll
crSizeNESW
crSizeNS
crSizeNWSE
crSizeWE
crSQLWait
crUpArrow
crVSplit

(3) On the ComboBox1Change procedure add this code:

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
     Form1.Cursor := StringToCursor(ComboBox1.Text);
end;

This will allow you to select the cursor type from the ComboBox and see it when you move the mouse over the Form. Only when you hover over the ComboBox will the cursor return to the default (crDefault).




EXAMPLE 2: Change An Objects Cursor

procedure TForm1.FormCreate(Sender: TObject);
begin
     Form1.Cursor := crHourGlass;
     // Changes the Form1 cursor to an hour glass.

     Button1.Cursor := crHourGlass;
     // Changes the Button1 cursor to an hour glass.

     Memo1.Cursor := crHourGlass;
     // Changes the Memo1 cursor to an hour glass.
end;




EXAMPLE 3: Change All Controls To An Hour Glass, Except TBitBtn Controls

procedure TForm1.FormCreate(Sender: TObject);
var
   I: Integer;
begin
     Form1.Cursor := crHourGlass;
     for I := 0 to Form1.ControlCount - 1 do
     begin
          if (Form1.Controls[I].ClassType <> TBitBtn) then
             Form1.Controls[I].Cursor := crHourGlass;
     end;
end;

However, if you had a GroupBox, you would have to address the controls within it separately.

procedure TForm1.FormCreate(Sender: TObject);
var
   I: Integer;
begin
     Form1.Cursor := crHourGlass;
     for I := 0 to Form1.ControlCount - 1 do
     begin
          if (Form1.Controls[I].ClassType <> TBitBtn) then
             Form1.Controls[I].Cursor := crHourGlass;
     end;
     for I := 0 to Form1.GroupBox1.ControlCount - 1 do
     begin
          if (Form1.GroupBox1.Controls[I].ClassType <> TBitBtn) then
             Form1.GroupBox1.Controls[I].Cursor := crHourGlass;
     end;
end;

With the above example, in which you had Form1, as well as other controls on the form such as Memo1, Edit1, Image1, BitBtn, etc., this would change all but the BitBtn controls to the Hour Glass. There are controls such as the TGroupBox, TPanel, that act as individual containers for controls, and these items must be addresses separately from the main Form in order to change their internal control set to a different cursor at runtime.