Public Overridable Property Cursor As Cursor将 Cursor 分配给控件的 Cursor 属性,以便更改在鼠标指针位于该控件上时显示的光标。要临时更改应用程序上所有控件的鼠标光标,请设置 Cursor.Current 属性。在填充 ComboBox 或者在保存或加载文件时,通常应将 Cursor.Current 属性设置为等待光标。
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: [email protected] // 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); } } }
{
try
{
Cursor = Cursors.WaitCursor;
//数据处理....
}
finally
{
Cursor = Cursors.Default;
}
}
设定Cursors.WaitCursor后,如果Load Data过程不是多线程或异步调用,应用程序是处于等待状态,Mouse应该一直是WaitCursor的啊
-----------------
我想问一下这样起什么作用先?
可以把Form的Title禁用嘛!
除非你把它移动到下面的任务栏才会变。
但如果要求移动到任务栏也还是沙漏的话,那确实很BT了,也不符合用户习惯阿。
就像你的程序加入死掉了,我把鼠标移到任务管理器上还是等待状态,那岂不是很别扭?
try
{
Cursor = Cursors.WaitCursor;
//数据处理....
}
finally
{
Cursor = Cursors.Default;
}
}
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: [email protected]
// 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);
}
}
}