locked
Mouse.OverrideCursor not found! RRS feed

  • Question

  • I need to temporarily override my mouse cursor with my own custom cursor.  All the literature tells me to use the construct:

    Mouse.OverrideCursor = MyCustomCursor

    However, when I apply this code I get the error message:   

    Error BC30456   'OverrideCursor' is not a member of 'Mouse'.

    The only options that VS 2019 suggests for Mouse.  are:   Equals  and  ReferenceEquals.

    I am clearly missing something but I have not been able to find it.  Any clues or help please?

    HotIndigo.


    • Edited by HotIndigo Friday, November 6, 2020 1:15 AM
    Friday, November 6, 2020 1:12 AM

All replies

  • The following is in a window in a WPF project. Changes the cursor to wait for five seconds.

    Imports System.Threading
    Class MainWindow
        Private Sub Demo()
            Task.Factory.StartNew(
                Sub()
                    Windows.Application.Current.Dispatcher.Invoke(Sub() Mouse.OverrideCursor = Cursors.Wait)
                    Try
                        Thread.Sleep(5000)
                    Finally
                        Windows.Application.Current.Dispatcher.Invoke(Sub() Mouse.OverrideCursor = Nothing)
                    End Try
                End Sub)
        End Sub
    End Class


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Friday, November 6, 2020 3:44 AM
  • Just change the Cursor property (or Cursor.Current)
    • Edited by Castorix31 Friday, November 6, 2020 7:35 AM
    • Proposed as answer by valat Friday, November 6, 2020 4:01 PM
    Friday, November 6, 2020 7:33 AM
  • Thanks for the suggestion.  I tried it and get this error message:

      Error BC30456 'Application' is not a member of 'System.Windows'

    I suspect it is to do with the fact I am writing in a VB .Net project and not WPF (but then again, I'm not that familiar with WPF).  Is there another way to invoke the override?

    HotIndigo.

    Friday, November 6, 2020 3:33 PM
  • Thanks for the suggestion.  I tried it and get this error message:

      Error BC30456 'Application' is not a member of 'System.Windows'

    I suspect it is to do with the fact I am writing in a VB .Net project and not WPF (but then again, I'm not that familiar with WPF).  Is there another way to invoke the override?

    HotIndigo.

    I'm use a plain Jane VB.NET WPF project with Framework 4.7.2 and have zero issues. All I did was create the following (full source is here)

    Imports System.Threading
    
    Public Class CursorExample
        Public Shared Sub Change()
    
            Task.Factory.StartNew(
                        Sub()
                            Windows.Application.Current.Dispatcher.Invoke(Sub() Mouse.OverrideCursor = Cursors.Wait)
                            Try
                                Thread.Sleep(5000)
                            Finally
                                Windows.Application.Current.Dispatcher.Invoke(Sub() Mouse.OverrideCursor = Nothing)
                            End Try
                        End Sub)
    
        End Sub
    End Class
    
    And called it from code behind in a button click


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Friday, November 6, 2020 3:58 PM
  • Still getting the BC30456 error message about "Application"!  Any other way of invoking  Mouse.OverrideCursor?

    HotIndigo.

    Friday, November 6, 2020 6:12 PM
  • Still getting the BC30456 error message about "Application"!  Any other way of invoking  Mouse.OverrideCursor?

    HotIndigo.

    You got the answer : Cursor property
    Friday, November 6, 2020 7:13 PM
  • I have tried Cursor property but I still cannot get the Mouse. dropdown menu to give me the option of OverrideCursor.  Further searching has not uncovered any way of overriding the mouse cursor. Mouse.Cursor = MyCursor  has no effect on the cursor.

    HotIndigo.

    Saturday, November 7, 2020 6:49 PM
  •  I suspect it is to do with the fact I am writing in a VB .Net project and not WPF

    Mouse.OverrideCursor is WPF

    • Edited by Castorix31 Saturday, November 7, 2020 8:32 PM
    Saturday, November 7, 2020 7:12 PM
  • Thanks for the heads up.  I don't suppose there is a VB way of performing Mouse.OverrideCursor?
    Saturday, November 7, 2020 11:42 PM
  • Still getting the BC30456 error message about "Application"!  Any other way of invoking  Mouse.OverrideCursor?

    HotIndigo.

    Did you run my example as per the link below which I gave out earlier?

    https://github.com/karenpayneoregon/visual-basic-getting-started/tree/master/ChangeCursor


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Sunday, November 8, 2020 12:07 AM
  • Thanks for the heads up.  I don't suppose there is a VB way of performing Mouse.OverrideCursor?

    But if you're on Winforms,  Cursor property or Cursor.Current

    A simple test showing it works :

                Cursor.Current = Cursors.WaitCursor
                System.Threading.Thread.Sleep(2000)
                Cursor.Current = Cursors.Arrow


    • Edited by Castorix31 Sunday, November 8, 2020 7:45 AM
    Sunday, November 8, 2020 7:37 AM