且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在Windows应用程序中显示带有消息的等待光标

更新时间:2023-10-26 21:27:40

请参阅基于IDisposable和"using"的 safe 解决方案:
>沙漏鼠标光标始终会变回其原始图像. [ ^ ].

—SA
Please see my safe solution based on IDisposable and "using":
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[^].

—SA



在调用昂贵的操作之前,可以通过以下代码设置光标:
Hi,
before calling the expensive operation you can set up the cursor via this code:
this.Cursor = Cursors.WaitCursor;


操作结束后,将其重新设置:


after the operation ends, set it back:

this.Cursor = Cursors.Default;


问候


私有无效button1_Click(对象发送者,EventArgs e)
{
DialogResult dr = MessageBox.Show(使用等待游标",顶部",MessageBoxButtons.OKCancel);


如果(dr == DialogResult.OK)
{
光标= Cursors.WaitCursor;

为(int i = 0; i< 1000000000; i ++)
{


}

Cursor = Cursors.Default;
}




}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Use of wait cursor", "Top", MessageBoxButtons.OKCancel);


if (dr==DialogResult.OK)
{
Cursor = Cursors.WaitCursor;

for (int i = 0; i < 1000000000; i++)
{


}

Cursor = Cursors.Default;
}




}