如何在Windows窗体中显示等待光标 [英] how to show a wait cursor in windows form

查看:66
本文介绍了如何在Windows窗体中显示等待光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理数据库编码的Windows窗体。

它非常简单的代码,但它需要将近4秒才能完成。但我想显示等待光标或应用程序启动光标是代码已声明,如果代码结束,光标将返回默认箭头。

我的代码是这样的

i have a windows form which deals with database coding.
its quite simple code but it takes almost 4 sec to complete. but i want to show wait cursor or app starting cursor is the code is stated and the cursor with be back to default arrow if the code ends.
my code is like this

bool IsMatchedFound = false;
                   SqlConnection con = new SqlConnection();
                   con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\sample project\prject xample2 perfect\login\Database1.mdf;Integrated Security=True;User Instance=True";
                   try
                   {
                       con.Open();
                       string qry1 = "Select * from Table1 WHERE password = @password COLLATE SQL_Latin1_General_CP1_CS_AS and Username=@Username COLLATE SQL_Latin1_General_CP1_CS_AS";
                       SqlCommand com = new SqlCommand(qry1, con);
                       com.Parameters.AddWithValue("@Username", this.usernamelabel.Text);
                       com.Parameters.AddWithValue("@Password", this.textBox1.Text);
                       SqlDataReader dr = com.ExecuteReader();
                       while (dr.Read())
                       {
                           if (dr.HasRows == true)
                           {
                               IsMatchedFound = true;
                               break;
                           }
                       }

                   }
                   catch (Exception)
                   {
                       MessageBox.Show("Error with the databse connection");
                   }
                   con.Close();
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.ToString());
               }

推荐答案





试试这个:

Hi,

Try this:
this.Cursor = Cursors.WaitCursor;



有关C#Windows窗体中游标的更多信息: http:// www.c-sharpcorner.com/uploadfile/mahesh/cursors-in-C-Sharp/ [ ^ ]



希望这有帮助。


More about cursors in C# Windows Forms: http://www.c-sharpcorner.com/uploadfile/mahesh/cursors-in-C-Sharp/[^]

Hope this helps.


嗨亲爱的,



hi dear,

//cursor activities is wait cursor
Cursor = Cursors.WaitCursor;

//cursor activities is default.
Cursor = Cursors.Default;


这篇关于如何在Windows窗体中显示等待光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆