RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCategoryButtons.Cursor Property

Specifies the image used to represent the mouse pointer when it passes into the region covered by the control.

Pascal
property Cursor: TCursor;
C++
__property TCursor Cursor;

Change the value of Cursor to provide feedback to the user when the mouse pointer enters the control. The value of Cursor is the index of the cursor in the list of cursors maintained by the global variable, Screen. In addition to the built-in cursors provided by TScreen, applications can add custom cursors to the list.  

C++ Examples: 

 

/*
This example uses a splitter and two image controls to
create a "slide show" effect.  The example displays an image
(the current "slide"), which can be hidden behind a screen
that looks like a venetian blind. When the blind is pulled
down to completely cover the current slide, the slide changes
to a different image.  When the blind is raised, the new
image appears.
To prepare this example, follow these steps:
1. Place an image control on the form.
Set the picture property to a bitmap of a venetian blind,
Set the Stretch property to True.
Set the Align property to alTop.
2. Add a splitter control to the form.
Set the Align property to alTop.
Set the Cursor property to crVSplit.
Set the OnMoved event handler to the code that appears below.
Set the MinSize property to 1.
3. Add a second image control to the form.
Set the Align property to alClient.
Set the Stretch property to True.
4. Select the form and add the OnCreate and OnDestroy event
   handlers that appear below.
5. Add the global variables below to the unit.
*/
int CurImage;
Graphics::TBitmap *BMPs[5];

void __fastcall TForm1::Splitter1Moved(TObject *Sender)
{
  // check if the blind is closed
  if (Image2->Height <= 1)
  {
    // the blind is closed, change the current slide
    CurImage++;
    if (CurImage == 5)
       CurImage = 0;
    Image2->Picture->Bitmap = BMPs[CurImage];
  }
}

#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // Initialize the array of slides.
  // These must be freed in the OnDestroy event handler.

  static std::auto_ptr<Graphics::TBitmap> _MyBMP0Cleaner(BMPs[0] = new Graphics::TBitmap);
  BMPs[0]->LoadFromFile("..\\factory.bmp");

  static std::auto_ptr<Graphics::TBitmap> _MyBMP1Cleaner(BMPs[1] = new Graphics::TBitmap);
  BMPs[1]->LoadFromFile("..\\Rhododendron.bmp");

  static std::auto_ptr<Graphics::TBitmap> _MyBMP2Cleaner(BMPs[2] = new Graphics::TBitmap);
  BMPs[2]->LoadFromFile("..\\littleB_64.bmp");

  static std::auto_ptr<Graphics::TBitmap> _MyBMP3Cleaner(BMPs[3] = new Graphics::TBitmap);
  BMPs[3]->LoadFromFile("..\\Soap Bubbles.bmp");

  static std::auto_ptr<Graphics::TBitmap> _MyBMP4Cleaner(BMPs[4] = new Graphics::TBitmap);
  BMPs[4]->LoadFromFile("..\\Gone Fishing.bmp");

  CurImage = 0;

  Image2->Picture->Bitmap = BMPs[0];
}
/*
This example shows how to add custom cursors to an
application.  The following code makes this cursor available
to the application via the constant crMyCursor, and sets it
as the global cursor to the application.
*/

#include <memory>       //for STL auto_ptr class

const crMyCursor = 5;

  void __fastcall TForm1::Button2Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> bmpMask(new Graphics::TBitmap);
  std::auto_ptr<Graphics::TBitmap> bmpColor(new Graphics::TBitmap);
  std::auto_ptr<TIconInfo> iconInfo(new TIconInfo);

  bmpMask->LoadFromFile("../SquareMask.bmp");
  bmpColor->LoadFromFile("../Square.bmp");

  iconInfo->fIcon = false;
  iconInfo->xHotspot = 15;
  iconInfo->yHotspot = 15;
  iconInfo->hbmMask = bmpMask->Handle;
  iconInfo->hbmColor = bmpColor->Handle;

  Screen->Cursors[crMyCursor] = CreateIconIndirect(iconInfo.get());

  Screen->Cursor = crMyCursor;
}

 

Delphi Examples: 

{
This example uses a splitter and two image controls to
create a "slide show" effect.  The example displays an image
(the current "slide"), which can be hidden behind a screen
that looks like a venetian blind. When the blind is pulled
down to completely cover the current slide, the slide changes
to a different image.  When the blind is raised, the new
image appears.
To prepare this example, follow these steps:
1. Place an image control on the form.  
Set the picture property to a bitmap of a venetian blind, 
Set the Stretch property to True.
Set the Align property to alTop.
2. Add a splitter control to the form.
Set the Align property to alTop.
Set the Cursor property to crVSplit.
Set the OnMoved event handler to the code that appears below.
Set the MinSize property to 1.
3. Add a second image control to the form.
Set the Align property to alClient.
Set the Stretch property to True.
4. Select the form and add the OnCreate and OnDestroy event
   handlers that appear below.
5. Add the global variables below to the unit.
}
var
  CurImage: Integer;
  BMPs: Array[1..5] of TBitmap;

procedure TForm1.Splitter1Moved(Sender: TObject);
begin
  { check if the blind is closed }
  if Image2.Height <= 1 then
  begin
    { the blind is closed, change the current slide }
    CurImage := CurImage + 1;
    if CurImage = 6 then
       CurImage := 1;
    Image2.Picture.Bitmap := BMPs[CurImage];
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Initialize the array of slides.
    These must be freed in the OnDestroy event handler. }
  BMPs[1] := TBitmap.Create;
  BMPs[1].LoadFromFile('Factory.bmp');
  BMPs[2] := TBitmap.Create;
  BMPs[2].LoadFromFile('Rhododendron.bmp');
  BMPs[3] := TBitmap.Create;
  BMPs[3].LoadFromFile('littleB_64.bmp');
  BMPs[4] := TBitmap.Create;
  BMPs[4].LoadFromFile('Soap bubbles.bmp');
  BMPs[5] := TBitmap.Create;
  BMPs[5].LoadFromFile('Gone Fishing.bmp');
  CurImage := 1;
  Image2.Picture.Bitmap := BMPs[1];
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  I: Integer;
begin
  { clean up }
  for I := 1 to 5 do
    BMPs[I].Free;
end;
{
This example shows how to add custom cursors to an
application.  The following code makes this cursor available
to the application via the constant crMyCursor, and sets it
as the global cursor to the application.
} 
var
  bmpMask : TBitmap;
  bmpColor : TBitmap;
  iconInfo : TIconInfo;
const
  crMyCursor = 5;

procedure TForm1.Button2Click(Sender: TObject);
begin
  bmpMask := TBitmap.Create;
  bmpColor := TBitmap.Create;

  bmpMask.LoadFromFile('SquareMask.bmp');
  bmpColor.LoadFromFile('Square.bmp');

  with iconInfo do
  begin
    fIcon := false;
    xHotspot := 15;
    yHotspot := 15;
    hbmMask := bmpMask.Handle;
    hbmColor := bmpColor.Handle;
  end;

  Screen.Cursors[crMyCursor] := CreateIconIndirect(iconInfo);
  
  Screen.Cursor := crMyCursor;

  bmpMask.Free;
  bmpColor.Free;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DestroyIcon(Screen.Cursors[crMyCursor]);
end;

 

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