xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Classes | Static Public Attributes | Public Member Functions | Static Public Member Functions | List of all members
xtd::forms::cursor Class Reference

#include <cursor.h>

Definition

Represents the image used to paint the mouse pointer.

Namespace
xtd::forms
Library
xtd.forms
Remarks
A cursor is a small picture whose location on the screen is controlled by a pointing device, such as a mouse, pen, or trackball. When the user moves the pointing device, the operating system moves the cursor accordingly.
Different cursor shapes are used to inform the user what operation the mouse will have. For example, when editing or selecting text, a cursors::ibeam cursor is typically displayed. A wait cursor is commonly used to inform the user that a process is currently running. Examples of processes you might have the user wait for are opening a file, saving a file, or filling a control such as a data_grid, list_box or tree_view with a large amount of data.
All controls that derive from the Control class have a Cursor property. To change the cursor displayed by the mouse pointer when it is within the bounds of the control, assign a Cursor to the Cursor property of the control. Alternatively, you can display cursors at the application level by assigning a Cursor to the Current property. For example, if the purpose of your application is to edit a text file, you might set the Current property to Cursors.WaitCursor to display a wait cursor over the application while the file loads or saves to prevent any mouse events from being processed. When the process is complete, set the Current property to Cursors.Default for the application to display the appropriate cursor over each control type.
See also
xtd::forms::cursors
Examples
The following code example demonstrate the use of cursor component.
#include <xtd/xtd>
using namespace std;
using namespace xtd;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
text("Cursor example");
start_position(form_start_position::manual);
location({200, 200});
client_size({360, 240});
list_box_cursors.parent(*this);
list_box_cursors.bounds({20, 20, 150, 200});
list_box_cursors.items().push_back_range({{"Default", cursors::default_cursor()}, {"Application Starting", cursors::app_starting()}, {"Arrow", cursors::arrow()}, {"Closed hand", cursors::closed_hand()}, {"Contextual menu", cursors::contextual_menu()}, {"Cell", cursors::cell()}, {"Cross", cursors::cross()}, {"Disappearing item", cursors::disappearing_item()}, {"Drag copy", cursors::drag_copy()}, {"Drag link", cursors::drag_link()}, {"Hand", cursors::hand()}, {"Help", cursors::help()}, {"Horizontal split", cursors::hsplit()}, {"I beam", cursors::ibeam()}, {"No", cursors::no()}, {"No drag", cursors::no_drag()}, {"No move 2d", cursors::no_move_2d()}, {"No move horizontal", cursors::no_move_horiz()}, {"No move vertical", cursors::no_move_vert()}, {"Open hand", cursors::open_hand()}, {"Pan east", cursors::pan_east()}, {"Pan north east", cursors::pan_ne()}, {"Pan north", cursors::pan_north()}, {"Pan north west", cursors::pan_nw()}, {"Pan south east", cursors::pan_se()}, {"Pan south", cursors::pan_south()}, {"Pan south west", cursors::pan_sw()}, {"Pan West", cursors::pan_west()}, {"Size all", cursors::size_all()}, {"Size north-east south-west", cursors::size_nesw()}, {"Size north south", cursors::size_ns()}, {"Size north-west south-east", cursors::size_nwse()}, {"Size west east", cursors::size_we()}, {"Up arrow", cursors::up_arrow()}, {"Vertical I beam", cursors::vibeam()}, {"Vertical split", cursors::vsplit()}, {"Wait", cursors::wait_cursor()}, {"Zoom in", cursors::zoom_in()}, {"Zoom out", cursors::zoom_out()}});
list_box_cursors.selected_index_changed += [&] {
test_zone.cursor(any_cast<forms::cursor>(list_box_cursors.selected_item().tag()));
};
list_box_cursors.selected_item("Default");
test_zone.parent(*this);
test_zone.border_style(border_style::fixed_3d);
test_zone.back_color(drawing::system_colors::window());
test_zone.bounds({190, 20, 150, 200});
}
private:
list_box list_box_cursors;
panel test_zone;
};
int main() {
application::run(form1());
}
static xtd::drawing::color window()
Gets a system-defined color that has an ARGB value of 0xFFFFFFFF. This field is constant.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static cursor size_all()
Gets the four-headed sizing cursor, which consists of four joined arrows that point north,...
static cursor size_nesw()
Gets the two-headed diagonal (northeast/southwest) sizing cursor.
static cursor wait_cursor()
Gets the wait cursor, typically an hourglass shape.
static cursor ibeam()
Gets the I-beam cursor, which is used to show where the text cursor appears when the mouse is clicked...
static cursor no()
Gets the cursor that indicates that a particular region is invalid for the current operation.
static cursor size_ns()
Gets the two-headed vertical (north/south) sizing cursor.
static cursor pan_sw()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor pan_west()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor hsplit()
Gets the cursor that appears when the mouse is positioned over a horizontal splitter bar.
static cursor no_drag()
Gets the cursor that indicates that a particular region is invalid for the current drag & drop operat...
static cursor contextual_menu()
Gets the contextual menu cursor.
static cursor disappearing_item()
Gets the disappearing item cursor.
static cursor size_we()
Gets the two-headed diagonal (northwest/southeast) sizing cursor.
static cursor cell()
Gets the cell cursor.
static cursor app_starting()
Gets the cursor that appears when an application starts.
static cursor pan_north()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor arrow()
Gets the arrow cursor.
static cursor cross()
Gets the crosshair cursor.
static cursor pan_nw()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor size_nwse()
Gets the two-headed diagonal (northwest/southeast) sizing cursor.
static cursor no_move_vert()
Gets the cursor that appears during wheel operations when the mouse is not moving,...
static cursor up_arrow()
Gets the up arrow cursor, typically used to identify an insertion point.
static cursor drag_copy()
Gets the drag copy cursor.
static cursor open_hand()
Gets the open hand cursor.
static cursor zoom_out()
Gets the zoom out cursor, typically to zoom out an object.
static cursor pan_se()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor default_cursor()
Gets the default cursor, which is usually an arrow cursor.
static cursor no_move_horiz()
Gets the cursor that appears during wheel operations when the mouse is not moving,...
static cursor vibeam()
Gets the vertical I-beam cursor, which is used to show where the text cursor appears when the mouse i...
static cursor drag_link()
Gets the drag link cursor.
static cursor help()
Gets the Help cursor, which is a combination of an arrow and a question mark.
static cursor hand()
Gets the hand cursor, typically used when hovering over a Web link.
static cursor pan_south()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor closed_hand()
Gets the closed hand cursor.
static cursor vsplit()
Gets the cursor that appears when the mouse is positioned over a vertical splitter bar.
static cursor pan_east()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
static cursor no_move_2d()
Gets the cursor that appears during wheel operations when the mouse is not moving,...
static cursor zoom_in()
Gets the zoom int cursor, typically to zoom in an object.
static cursor pan_ne()
Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrol...
@ location
Specifies that both the x and y coordinates of the control are defined.
@ fixed_3d
A three-dimensional border.
@ bottom
The parent form of this multiple document interface (MDI) form is closing.
@ right
The Microsoft Windows Task Manager is closing the application.
@ left
The user is closing the form through the user interface (UI), for example by clicking the Close butto...
@ top
The operating system is closing all applications before shutting down.
@ manual
The position of the form is determined by the Location property.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17

Inherits xtd::object.

Static Public Attributes

static cursor none
 Represent none cursor. More...
 

Public Member Functions

 cursor ()
 Initializes a new instance of the cursor class. More...
 
 cursor (intptr_t handle)
 Initializes a new instance of the Cursor class from the specified Windows handle. More...
 
intptr_t copy_handle () const
 Copies the handle of this cursor. More...
 
intptr_t handle () const
 Gets the handle of the cursor. More...
 
drawing::point hot_spot () const
 Gets the cursor hot spot. More...
 
drawing::size size () const
 Gets the size of the cursor object. More...
 
std::any tag () const
 Gets the object that contains data about the control. More...
 
void tag (std::any tag)
 Sets the object that contains data about the control. More...
 
xtd::ustring to_string () const noexcept override
 Returns a string containing the name of the cursor. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 

Static Public Member Functions

static xtd::forms::cursor current ()
 Gets a cursor object that represents the mouse cursor. More...
 
static void current (const xtd::forms::cursor &cursor)
 Sets a cursor object that represents the mouse cursor. More...
 
static cursor from_bitmap (const xtd::drawing::bitmap &bitmap)
 Create a cursor form a specified bitmap. More...
 
static cursor from_bitmap (const xtd::drawing::bitmap &bitmap, const xtd::drawing::point &hot_spot)
 Create a cursor form a specified bitmap with specified hot spot. More...
 
static void hide ()
 Hides the cursor. More...
 
static drawing::point position ()
 Gets the cursor's position. More...
 
static void position (const drawing::point &position)
 Sets the cursor's position. More...
 
static void show ()
 Displays the cursor. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ cursor() [1/2]

xtd::forms::cursor::cursor ( )

Initializes a new instance of the cursor class.

◆ cursor() [2/2]

xtd::forms::cursor::cursor ( intptr_t  handle)
inlineexplicit

Initializes a new instance of the Cursor class from the specified Windows handle.

Parameters
handleAn IntPtr that represents the Windows handle of the cursor to create.
Remarks
You must free the cursor handle when you are done with it.

Member Function Documentation

◆ copy_handle()

intptr_t xtd::forms::cursor::copy_handle ( ) const

Copies the handle of this cursor.

Returns
An intptr_t that represents the cursor's handle.
Remarks
The handle created as a result of calling this method must be deleted of when you are done with it.

◆ current() [1/2]

static xtd::forms::cursor xtd::forms::cursor::current ( )
static

Gets a cursor object that represents the mouse cursor.

Returns
A cursor that represents the mouse cursor. The default is cursor::none.
Remarks
Setting the current property changes the cursor currently displayed. The application may or may not continue to listen for mouse events. To signal that the application should not respond to mouse events during a long-running operation, use the application::use_wait_cursor property. In most cases, however, it's better to use a background thread to manage a long-running operation, and leave your user interface accessible to the user.

◆ current() [2/2]

static void xtd::forms::cursor::current ( const xtd::forms::cursor cursor)
static

Sets a cursor object that represents the mouse cursor.

Parameters
cursorA cursor that represents the mouse cursor. The default is cursor::none.
Remarks
Setting the current property changes the cursor currently displayed. The application may or may not continue to listen for mouse events. To signal that the application should not respond to mouse events during a long-running operation, use the application::use_wait_cursor property. In most cases, however, it's better to use a background thread to manage a long-running operation, and leave your user interface accessible to the user.

◆ from_bitmap() [1/2]

static cursor xtd::forms::cursor::from_bitmap ( const xtd::drawing::bitmap bitmap)
inlinestatic

Create a cursor form a specified bitmap.

Parameters
bitmapA xtd::drawing::bitmap image will be use by cursor.
Returns
A new cursor instance.
Remarks
The hot spot location is top left (0, 0).

◆ from_bitmap() [2/2]

static cursor xtd::forms::cursor::from_bitmap ( const xtd::drawing::bitmap bitmap,
const xtd::drawing::point hot_spot 
)
inlinestatic

Create a cursor form a specified bitmap with specified hot spot.

Parameters
bitmapA xtd::drawing::bitmap image will be use by cursor.
hot_spotA xtd::drawing::point hot spot location.
Returns
A new cursor instance.

◆ handle()

intptr_t xtd::forms::cursor::handle ( ) const
inline

Gets the handle of the cursor.

Returns
An intptr_t that represents the cursor's handle.
Remarks
This is not a copy of the handle; do not destroy it.

◆ hide()

static void xtd::forms::cursor::hide ( )
static

Hides the cursor.

The show and hide method calls must be balanced. For every call to the hide method there must be a corresponding call to the show method.

◆ hot_spot()

drawing::point xtd::forms::cursor::hot_spot ( ) const
inline

Gets the cursor hot spot.

Returns
A point representing the cursor hot spot.
Remarks
The hot_spot is the point in the cursor that interacts with other elements on the screen.

◆ position() [1/2]

static drawing::point xtd::forms::cursor::position ( )
static

Gets the cursor's position.

Returns
A point that represents the cursor's position in screen coordinates.
Remarks
The position property is identical to the control::mouse_position property.

◆ position() [2/2]

static void xtd::forms::cursor::position ( const drawing::point position)
static

Sets the cursor's position.

Parameters
positionA point that represents the cursor's position in screen coordinates.
Remarks
The position property is identical to the control::mouse_position property.

◆ show()

static void xtd::forms::cursor::show ( )
static

Displays the cursor.

The show and hide method calls must be balanced. For every call to the hide method there must be a corresponding call to the show method.

◆ size()

drawing::size xtd::forms::cursor::size ( ) const
inline

Gets the size of the cursor object.

Returns
A size that represents the width and height of the cursor.

◆ tag() [1/2]

std::any xtd::forms::cursor::tag ( ) const
inline

Gets the object that contains data about the control.

Returns
A std::any that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.

◆ tag() [2/2]

void xtd::forms::cursor::tag ( std::any  tag)
inline

Sets the object that contains data about the control.

Parameters
tagA std::any that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.

◆ to_string()

xtd::ustring xtd::forms::cursor::to_string ( ) const
overridevirtualnoexcept

Returns a string containing the name of the cursor.

Returns
A string containing the name of the cursor.

Reimplemented from xtd::object.

Member Data Documentation

◆ none

cursor xtd::forms::cursor::none
static

Represent none cursor.


The documentation for this class was generated from the following file: