开发者

What is a Cursor File in .NET?

I saw the Cursor File in the dialog box开发者_JAVA百科 when adding a new item. Actually what it will do and what is the use of it ?...Thanks..


It contains the Image(s) to draw a Cursor (mousepointer) on your screen.


From MSDN:

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.

You can use Visual Studio to create Cursor Files (.cur) which can then be loaded using the Windows Forms Cursor class or Win32 API calls such as LoadImage.


Start a new project from the Windows Forms Application template. Project + Add New Item, select Cursor File. Draw something. Project + Properties, Resources tab. Drag and drop the cursor onto the resource window so a resource is added. Make your form constructor look like this:

    public Form1() {
        InitializeComponent();
        this.Cursor = new Cursor(new System.IO.MemoryStream(Properties.Resources.Cursor1));
    }

Press F5 and have a look-see at your new mouse cursor.


If you want to change the cursor when it hovers above an object on your user interface and you are not satisfied with the builtin cursor you can create a custom cursor. Custorm cursors is like a small image, but has some extra properties:

  • Transparency mask so the cursor can have a shape that is not rectangular.
  • Hotspot location used to determine the mouse coordinates when the cursor is moved. Some cursors have the hotspot in the upper left corner (e.g. the arrow) while other have in the middle (e.g. the cross-hair) etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜