MouseCursor

From REALbasicWiki

Jump to: navigation, search

The MouseCursor class is used to specify the mouse pointer associated with an object when the mouse is positioned over it. For example, if the mouse is over editable text, you should want to set the so-called "iBeam" cursor to show the user that he/she can select text or insert text somewhere. By contrast, if you want to inform the user that an item is dragable, you should display a "Hand Open" cursor which will turn into a 'HandClosed" cursor if the user actually grabs the object by clicking the mouse button. Changing the mouse cursor depending on the context really helps the end-user to understand what he/she will do. A mouse cursor can be attributed to a window or independently to any control inside it.

Contents

[edit] Built-in cursors

Pre-supplied settings include:

System.Cursors.ArrowAllDirections
System.Cursors.ArrowEastWest
System.Cursors.ArrowNortheastSouthwest
System.Cursors.ArrowNorthSouth
System.Cursors.ArrowNorthwestSoutheast
System.Cursors.FingerPointer
System.Cursors.HandClosed
System.Cursors.HandOpen
System.Cursors.Hide
System.Cursors.IBeam
System.Cursors.InvisibleCursor
System.Cursors.MagnifyLarger
System.Cursors.MagnifySmaller
System.Cursors.Show
System.Cursors.SplitterEastWest
System.Cursors.SplitterNorthSouth
System.Cursors.StandardPointer
System.Cursors.Wait

[edit] Sample Code

Sub MouseEnter()
if mEditing then
me.MouseCursor = System.Cursors.IBeam
else
me.MouseCursor = System.Cursors.FingerPointer
end if
End Sub

Sub MouseExit()
//reset cursor to System default
me.MouseCursor = Nil
End Sub

[edit] Custom cursor on Mac OS X

On Mac OS X, you can design your own black and white cursor using a resource editor such as Rezilla. Please read the user manual.

  1. Create a file from Rezilla with a ".rsrc" extension (just to use standard extensions).
  2. Create a 'curs' resource (this is the Apple reserved code for 'cursor') and set the ID (which will be the key to retrieve the resource).
  3. Draw your custom cursor and the corresponding mask
  4. Set the so-called 'hot spot'
  5. Save the file
  6. Drag and drop the file from the Finder to the project window (you only have to do that once). The file file should appear in italic within the project window.
  7. In your REALbasic project, use the following code wherever you want to use your custom cursor
me.MouseCursor = App.ResourceFork.GetCursor( your_cursor_ID )

[edit] Note

The REALbasic documentation says that you can create one 'resource fork' file for each 'curs' resource and use it by name in a MouseCursor = ... statement. Unfortunately, this does not work in some REALbasic versions.

Personal tools
related