如何设置系统光标Cursor的形状?

yxdmj 2005-07-20 11:19:03
最近客户提出个很BT的要求:

在Load Data时,要求Cursor为沙漏形状,而且当Mouse 移动到Form的Title时也一样.

我试了API的SetCursor,好像没作用?
...全文
2336 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
深山老翁 2005-07-20
  • 打赏
  • 举报
回复
当Mouse 移动到Form的Title时也一样
-----------------
我想问一下这样起什么作用先?
可以把Form的Title禁用嘛!
lovvver 2005-07-20
  • 打赏
  • 举报
回复
关注一下~
MyLf 2005-07-20
  • 打赏
  • 举报
回复
??
设定Cursors.WaitCursor后,如果Load Data过程不是多线程或异步调用,应用程序是处于等待状态,Mouse应该一直是WaitCursor的啊
yxdmj 2005-07-20
  • 打赏
  • 举报
回复
:D

你说的我当然知道,但这个只是在Form的工作区域生效,

客户要求的是在Form的标题栏,还有鼠标移出了此Form也要是沙漏
sskset 2005-07-20
  • 打赏
  • 举报
回复
这个要求很BT吗?这个是最基本的处理

button2_Click
{
try
{
Cursor = Cursors.WaitCursor;

//数据处理....
}
finally
{
Cursor = Cursors.Default;
}
}
liduke 2005-07-20
  • 打赏
  • 举报
回复
移出窗体外这个要求好像不太好,与window机制不合
yxdmj 2005-07-20
  • 打赏
  • 举报
回复
还是我自己搞定.

yxdmj 2005-07-20
  • 打赏
  • 举报
回复
using System;
using System.Runtime.InteropServices;

namespace WindowsApplication2
{
/// <summary>
/// Summary description for clsSetCursor.
/// </summary>
public class clsSetCursor
{
#region Const

const int OCR_WAIT = 32514;
const int OCR_NORMAL = 32512 ;
const int OCR_APPSTARTING =32650;

#endregion

#region API
[DllImport("user32.dll")] public static extern IntPtr LoadCursorFromFile( string fileName );
[DllImport("user32")] public static extern int SetSystemCursor(IntPtr hcur, int id) ;


[DllImport("user32.dll")] static extern IntPtr LoadCursor(int hInstance, int lpCunrsorName);


#endregion

public clsSetCursor()
{
//
// TODO: Add constructor logic here
//
// Private Const OCR_NORMAL = 32512
// Private Const IDC_SIZEALL = 32646&
// Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, ByVal id As Long) As Long
// Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
// Private Declare Function DestroyCursor Lib "user32" (ByVal hCursor As Long) As Long
// Private Sub Form_Load()
// 'KPD-Team 2001
// 'URL: http://www.allapi.net/
// 'E-Mail: KPDTeam@Allapi.net
// Dim hCursor As Long
// 'load the 'Size-All' cursos
// hCursor = LoadCursor(ByVal 0&, IDC_SIZEALL)
// 'replaces the contents of the system cursor specified by OCR_NORMAL with the contents of the 'size-all' cursor
// SetSystemCursor hCursor, OCR_NORMAL
// 'clean up
// DestroyCursor hCursor
// End Sub
}

public static void setToAppStarting()
{
IntPtr iP=LoadCursorFromFile(@"C:\Documents and Settings\Felix Lau\Desktop\appstart.ani");
// int i=0;
IntPtr ii=LoadCursor(0,OCR_APPSTARTING);
SetSystemCursor(iP,OCR_NORMAL);
}

public static void setToNormal()
{
//IntPtr ii=LoadCursor(0,OCR_NORMAL);
IntPtr iP=LoadCursorFromFile(@"C:\Documents and Settings\Felix Lau\Desktop\fillitup.ani");
SetSystemCursor(iP,OCR_NORMAL);
}

public static IntPtr getNormal()
{
//return LoadCursor(0,OCR_NORMAL);
return new IntPtr(0);
}
}
}
mademelaugh 2005-07-20
  • 打赏
  • 举报
回复
Public Overridable Property Cursor As Cursor

将 Cursor 分配给控件的 Cursor 属性,以便更改在鼠标指针位于该控件上时显示的光标。要临时更改应用程序上所有控件的鼠标光标,请设置 Cursor.Current 属性。在填充 ComboBox 或者在保存或加载文件时,通常应将 Cursor.Current 属性设置为等待光标。
silverseven7 2005-07-20
  • 打赏
  • 举报
回复
{
try
{
Cursor = Cursors.WaitCursor;

//数据处理....
}
finally
{
Cursor = Cursors.Default;
}
}
mademelaugh 2005-07-20
  • 打赏
  • 举报
回复
使用Cursor.current设置整个应用程序的光标。
cliff1002 2005-07-20
  • 打赏
  • 举报
回复
sskset(断点)的代码是正确的。

而且,就像楼主说要求的,移动到form的title时候,也是沙漏状的
除非你把它移动到下面的任务栏才会变。
但如果要求移动到任务栏也还是沙漏的话,那确实很BT了,也不符合用户习惯阿。
就像你的程序加入死掉了,我把鼠标移到任务管理器上还是等待状态,那岂不是很别扭?

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧