faq24.htm

来自「C++builder学习资料C++builder」· HTM 代码 · 共 98 行

HTM
98
字号


<HTML>

<HEAD>

   <TITLE>Change the mouse cursor.</TITLE>

   <META NAME="Author" CONTENT="Harold Howe">

</HEAD>

<BODY BGCOLOR="WHITE">



<CENTER>

<TABLE  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">



<TR>

<TD>







<H3>

Change the mouse cursor.

</H3>

<P>

 Most VCL controls have a <TT>Cursor</TT> property that allows you

to change the mouse cursor for that control's air space. This works OK when you

need to change the cursor for one control, but it falls short when you need to

set the cursor for the entire screen. For example, if you set the cursor

property of a form, the cursor will change back when it passes over a control

in the form. To change the cursor for the entire screen, use the <TT>Cursor</TT>

property of the global screen property.

</P>

<P>

The list below illustrates the stock values that you can assign to

<TT>Screen-&gt;Cursor</TT>.

<TT>

<UL>

<LI> crDefault

<LI> crNone

<LI> crArrow

<LI> crCross

<LI> crIBeam

<LI> crSize

<LI> crSizeNESW

<LI> crSizeNS

<LI> crSizeNWSE

<LI> crSizeWE

<LI> crUpArrow

<LI> crHourGlass

<LI> crDrag

<LI> crNoDrop

<LI> crHSplit

<LI> crVSplit

<LI> crMultiDrag

<LI> crSQLWait

<LI> crNo

<LI> crAppStart

<LI> crHelp

</UL>

</TT>

</P>

<P>

The steps below describe how to assign a custom cursor, instead of using the

stock cursors.

</P>

<P>

<B>Step 1:</B> Use the image editor to create a RES file that contains your custom

cursor. Add the RES file to the project.

</P>

<P>

<B>Step 2:</B> The available screen cursors, include the stock cursors listed

above, are all contained in the <TT>Cursors</TT> array property of

<TT>TScreen</TT>. You must load your cursor and add it to this array before you

can use it. Declare a constant that will serve as your cursor identifer and

array index. Then load in the cursor using the declared index value.

</P>

<pre>

<b>const</b> TCursor crMyCustomCursor<b>=</b><font color="blue">1</font><b>;</b>    <font color="navy">// ID for custom cursor</font>



<b>__fastcall</b> TForm1<b>:</b><b>:</b>TForm1<b>(</b>TComponent<b>*</b> Owner<b>)</b>

<b>:</b> TForm<b>(</b>Owner<b>)</b>

<b>{</b>

    <font color="navy">// load the cursor into the array.</font>

    <font color="navy">// "CURSOR1" is the string identifer set using the Image Editor</font>

    Screen<b>-></b>Cursors<b>[</b>crMyCustomCursor<b>]</b><b>=</b>LoadCursor<b>(</b><b>(</b><b>void</b><b>*</b><b>)</b> HInstance<b>,</b><font color="blue">"CURSOR1"</font><b>)</b><b>;</b>

<b>}</b>

</pre>

<P>

<B>Step 3:</B> Assign the new cursor the to <TT>Screen-&gt;Cursor</TT> property

whenever you want it to be the mouse cursor.

</P>

<pre>

Screen<b>-></b>Cursor <b>=</b> crMyCustomCursor<b>;</b>

</pre>



</TD> </TR>



</TABLE>

</CENTER>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?