Difference between revisions of "Cursor"

From Lazarus wiki
Jump to navigationJump to search
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Cursor}}
 
{{Cursor}}
<br>
+
 
Cursor - property of the TCursor Object.
+
Cursor - [[Property|property]] of the TCursor Object.
  
 
==List of cursor constants==
 
==List of cursor constants==
<table border="1">
 
  <tr>
 
    <td>Constant</td>
 
    <td>Integer value</td>
 
    <td>Shape</td>
 
  </tr>
 
  <tr>
 
    <td>crDefault</td>
 
    <td align="right">0</td>
 
    <td>[[Image:crArrow.png]]</td>
 
  </tr>
 
  <tr>
 
  <tr>
 
    <td>crNone</td>
 
    <td align="right">-1</td>
 
    <td>Invisible mouse pointer</td>
 
  </tr>
 
  <tr>
 
  <tr>
 
    <td>crArrow</td>
 
    <td align="right">-2</td>
 
    <td>[[Image:crArrow.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crCross</td>
 
    <td align="right">-3</td>
 
    <td>[[Image:crCross.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crIBeam</td>
 
    <td align="right">-4</td>
 
    <td>[[Image:crIBeam.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSize</td>
 
    <td align="right">-22</td>
 
    <td>[[Image:crSize.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSizeNESW</td>
 
    <td align="right">-6</td>
 
    <td>[[Image:crSizeNESW.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSizeNS</td>
 
    <td align="right">-7</td>
 
    <td>[[Image:crSizeNS.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSizeNWSE</td>
 
    <td align="right">-8</td>
 
    <td>[[Image:crSizeNWSE.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSizeWE</td>
 
    <td align="right">-9</td>
 
    <td>[[Image:crSizeWE.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crUpArrow</td>
 
    <td align="right">-10</td>
 
    <td>[[Image:crUpArrow.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crHourGlass</td>
 
    <td align="right">-11</td>
 
    <td>[[Image:crHourGlass.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crDrag</td>
 
    <td align="right">-12</td>
 
    <td>[[Image:crDrag.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crNoDrop</td>
 
    <td align="right">-13</td>
 
    <td>[[Image:crNoDrop.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crHSplit</td>
 
    <td align="right">-14</td>
 
    <td>[[Image:crHSplit.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crVSplit</td>
 
    <td align="right">-15</td>
 
    <td>[[Image:crVSplit.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crMultiDrag</td>
 
    <td align="right">-16</td>
 
    <td>[[Image:crMultiDrag.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crSQLWait</td>
 
    <td align="right">-17</td>
 
    <td>[[Image:crSQLWait.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crNo</td>
 
    <td align="right">-18</td>
 
    <td>[[Image:CrNo.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crAppStart</td>
 
    <td align="right">-19</td>
 
    <td>[[Image:crAppStart.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crHelp</td>
 
    <td align="right">-20</td>
 
    <td>[[Image:crHelp.png]]</td>
 
  </tr>
 
  <tr>
 
    <td>crHandPoint</td>
 
    <td align="right">-21</td>
 
    <td>[[Image:crHandPoint.png]]</td>
 
  </tr>
 
</table>
 
<br>
 
  
 +
{| class="wikitable"
 +
|-
 +
! Constant || Integer value ||Shape
 +
|-
 +
| crDefault || 0  || [[Image:crArrow.png]]
 +
|-
 +
| crNone  || -1  || Invisible mouse pointer
 +
|-
 +
| crArrow || -2 || [[Image:crArrow.png]]
 +
|-
 +
| crCross || -3 || [[Image:crCross.png]]
 +
|-
 +
| crIBeam || -4 || [[Image:crIBeam.png]]
 +
|-
 +
| crSize || -22 || [[Image:crSize.png]]
 +
|-
 +
| crSizeNESW || -6 || [[Image:crSizeNESW.png]]
 +
|-
 +
| crSizeNS || -7 || [[Image:crSizeNS.png]]
 +
|-
 +
|crSizeNWSE || -8 || [[Image:crSizeNWSE.png]]
 +
|-
 +
|crSizeWE || -9 || [[Image:crSizeWE.png]]
 +
|-
 +
|crUpArrow || -10 || |[[Image:crUpArrow.png]]
 +
|-
 +
|crHourGlass || -11 || [[Image:crHourGlass.png]]
 +
|-
 +
|crDrag || -12 || [[Image:crDrag.png]]
 +
|-
 +
|crNoDrop || -13 || |[[Image:crNoDrop.png]]
 +
|-
 +
|crHSplit || -14 || [[Image:crHSplit.png]]
 +
|-
 +
|crVSplit || -15 || |[[Image:crVSplit.png]]
 +
|-
 +
|crMultiDrag || -16 || [[Image:crMultiDrag.png]]
 +
|-
 +
|crSQLWait || -17 || [[Image:crSQLWait.png]]
 +
|-
 +
|crNo || -18 || [[Image:CrNo.png]]
 +
|-
 +
|crAppStart || -19 || [[Image:crAppStart.png]]
 +
|-
 +
|crHelp || -20 || [[Image:crHelp.png]]
 +
|-
 +
|crHandPoint || -21 || [[Image:crHandPoint.png]]
 +
|}
  
 
== Examples ==
 
== Examples ==
 
===Example 1: To View All The Cursor Types===
 
===Example 1: To View All The Cursor Types===
  
(1) On Form1, drag a ComboBox control onto the Form.
+
(1) On [[TForm|Form1]], drag a [[TComboBox|ComboBox]] control onto the Form.
  
 
(2) Set the ComboBox1, Items (TStrings) to the following:
 
(2) Set the ComboBox1, Items (TStrings) to the following:
  
crAppStart<br>
+
<syntaxhighlight lang="pascal">
crArrow<br>
+
crAppStart
crCross<br>
+
crArrow
crDefault<br>
+
crCross
crDrag<br>
+
crDefault
crHandPoint<br>
+
crDrag
crHelp<br>
+
crHandPoint
crHourGlass<br>
+
crHelp
crHSplit<br>
+
crHourGlass
crIBeam<br>
+
crHSplit
crMultiDrag<br>
+
crIBeam
crNo<br>
+
crMultiDrag
crNoDrop<br>
+
crNo
crNone<br>
+
crNoDrop
crSizeAll<br>
+
crNone
crSizeNESW<br>
+
crSizeAll
crSizeNS<br>
+
crSizeNESW
crSizeNWSE<br>
+
crSizeNS
crSizeWE<br>
+
crSizeNWSE
crSQLWait<br>
+
crSizeWE
crUpArrow<br>
+
crSQLWait
crVSplit<br><br>
+
crUpArrow
 +
crVSplit
 +
</syntaxhighlight>
 +
 
  
 
(3) On the ComboBox1Change procedure add this code:
 
(3) On the ComboBox1Change procedure add this code:
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
procedure TForm1.ComboBox1Change(Sender: TObject);
 
procedure TForm1.ComboBox1Change(Sender: TObject);
 
begin
 
begin
     Form1.Cursor := StringToCursor(ComboBox1.Text);
+
     Cursor := StringToCursor(ComboBox1.Text);
 
end;
 
end;
 
</syntaxhighlight>
 
</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).
 
  
 
===Example 2: Change An Objects Cursor===
 
===Example 2: Change An Objects Cursor===
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
begin
 
begin
     Form1.Cursor := crHourGlass;
+
     Cursor := crHourGlass;
 
     // Changes the Form1 cursor to an hour glass.
 
     // Changes the Form1 cursor to an hour glass.
  
Line 183: Line 113:
 
end;  
 
end;  
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
===Example 3: Change All Controls To An Hour Glass, Except TBitBtn Controls===
 
===Example 3: Change All Controls To An Hour Glass, Except TBitBtn Controls===
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
var
 
var
 
   I: Integer;
 
   I: Integer;
 
begin
 
begin
     Form1.Cursor := crHourGlass;
+
     Cursor := crHourGlass;
     for I := 0 to Form1.ControlCount - 1 do
+
     for I := 0 to ControlCount - 1 do
 
     begin
 
     begin
           if (Form1.Controls[I].ClassType <> TBitBtn) then
+
           if (Controls[I].ClassType <> TBitBtn) then
             Form1.Controls[I].Cursor := crHourGlass;
+
             Controls[I].Cursor := crHourGlass;
 
     end;
 
     end;
 
end;  
 
end;  
Line 203: Line 132:
 
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.
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
procedure TForm1.FormCreate(Sender: TObject);
 
procedure TForm1.FormCreate(Sender: TObject);
 
var
 
var
 
   I: Integer;
 
   I: Integer;
 
begin
 
begin
     Form1.Cursor := crHourGlass;
+
     Cursor := crHourGlass;
     for I := 0 to Form1.ControlCount - 1 do
+
     for I := 0 to ControlCount - 1 do
 
     begin
 
     begin
           if (Form1.Controls[I].ClassType <> TBitBtn) then
+
           if (Controls[I].ClassType <> TBitBtn) then
             Form1.Controls[I].Cursor := crHourGlass;
+
             Controls[I].Cursor := crHourGlass;
 
     end;
 
     end;
     for I := 0 to Form1.GroupBox1.ControlCount - 1 do
+
     for I := 0 to GroupBox1.ControlCount - 1 do
 
     begin
 
     begin
           if (Form1.GroupBox1.Controls[I].ClassType <> TBitBtn) then
+
           if (GroupBox1.Controls[I].ClassType <> TBitBtn) then
             Form1.GroupBox1.Controls[I].Cursor := crHourGlass;
+
             GroupBox1.Controls[I].Cursor := crHourGlass;
 
     end;
 
     end;
 
end;   
 
end;   
 
</syntaxhighlight>
 
</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 [[TMemo|Memo]], [[TEdit|Edit]], [[TImage|Image]], [[TBitBtn|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]].
 
 
[[Category:Lazarus]]
 
[[Category:GUI]]
 

Latest revision as of 20:35, 12 November 2020

Deutsch (de) English (en) suomi (fi)

Cursor - property of the TCursor Object.

List of cursor constants

Constant Integer value Shape
crDefault 0 crArrow.png
crNone -1 Invisible mouse pointer
crArrow -2 crArrow.png
crCross -3 crCross.png
crIBeam -4 crIBeam.png
crSize -22 crSize.png
crSizeNESW -6 crSizeNESW.png
crSizeNS -7 crSizeNS.png
crSizeNWSE -8 crSizeNWSE.png
crSizeWE -9 crSizeWE.png
crUpArrow -10 crUpArrow.png
crHourGlass -11 crHourGlass.png
crDrag -12 crDrag.png
crNoDrop -13 crNoDrop.png
crHSplit -14 crHSplit.png
crVSplit -15 crVSplit.png
crMultiDrag -16 crMultiDrag.png
crSQLWait -17 crSQLWait.png
crNo -18 CrNo.png
crAppStart -19 crAppStart.png
crHelp -20 crHelp.png
crHandPoint -21 crHandPoint.png

Examples

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
     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
     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
     Cursor := crHourGlass;
     for I := 0 to ControlCount - 1 do
     begin
          if (Controls[I].ClassType <> TBitBtn) then
             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
     Cursor := crHourGlass;
     for I := 0 to ControlCount - 1 do
     begin
          if (Controls[I].ClassType <> TBitBtn) then
             Controls[I].Cursor := crHourGlass;
     end;
     for I := 0 to GroupBox1.ControlCount - 1 do
     begin
          if (GroupBox1.Controls[I].ClassType <> TBitBtn) then
             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 Memo, Edit, Image, 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.