WinForms cursor hidden only on one Form

杀马特。学长 韩版系。学妹 提交于 2019-12-20 03:29:18

问题


I have a C# application with 2 simultaneous visible forms, and I need to hide mouse cursor when it is over only on one of them. If I use Cursor.Hide() it applies the change for both of them.


回答1:


You can make a "blank" cursor, and set myForm.Cursor = blankCursor; This will make that specific form show a specific cursor, which could be completely transparent.




回答2:


You need to implement this logic by using the MouseEnter and MouseLeave events one each form something like:

    private void frm1_MouseEnter(object sender, EventArgs e)
    {
       Cursor.Hide();
    }
    private void frm1_MouseLeave(object sender, EventArgs e)
    {
       Cursor.Show();
    }

do the abobe on the form that should hide the cursor and add this to the form that should make the cursor visible:

    private void frm2_MouseEnter(object sender, EventArgs e)
    {
       Cursor.Show();
    }



回答3:


Did you try this.Cursor = Cursors.None, instead of Cursor.Hide()?




回答4:


You could use the Control.MouseEnter and Control.MouseLeave events to trigger hiding or displaying the cursor




回答5:


If you're hiding the cursor so that the user can't do anything on the form, consider using this.UseWaitCursor = true; instead.



来源:https://stackoverflow.com/questions/2471982/winforms-cursor-hidden-only-on-one-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!