Displaying wait cursor in while backgroundworker is running

后端 未结 9 1702
傲寒
傲寒 2020-12-30 03:50

During the start of my windows application, I have to make a call to a web service to retrieve some default data to load onto my application. During the load of the form, I

9条回答
  •  隐瞒了意图╮
    2020-12-30 04:07

    Something else must be setting the cursor. The code below sets a wait cursor when the timer starts, and then sets the cursor back to the previous value after the timer expires. It works as expected: the wait cursor remains throughout the interval. Of course, moving the cursor outside the form will show the cursor for whatever window the mouse cursor is over, but moving it back to my form shows the wait cursor.

    public partial class MyDialog : Form
    {
        private Timer myTimer;
        public MyDialog()
        {
            InitializeComponent();
            myTimer = new Timer();
            myTimer.Tick += new EventHandler(myTimer_Tick);
            myTimer.Interval = 5000;
            myTimer.Enabled = false;
        }
    
        private Cursor SaveCursor;
        private void button1_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            myTimer.Enabled = true;
        }
    
        void myTimer_Tick(object sender, EventArgs e)
        {
            Cursor = SaveCursor;
            myTimer.Enabled = false;
        }
    }
    

提交回复
热议问题