What have you got so far?
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
You will need to enable KeyPreview in the form. You can trap the up arrow press in the forms KeyUp event. You have to enable KeyPreview at design time. There is no way to set it at run time so you will have to have a global variable (call it something like filterKeys) and set it to True in the button click event. Then in your KeyUp handler you can do
If filterKeys Then
.
.
.
End If
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
Dim filterKeys as Boolean
.
.
.
'in the ButtonClick event handler
filterKeys = True
However, if you don't know what a boolean is or how to set it then I suggest you do a lot more reading before you dive in.
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
See if this helps to get you started.
Public Class Form1
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyData
Case Keys.Up
Me.Cursor = Cursors.WaitCursor
End Select
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyData
Case Keys.Up
Me.Cursor = Cursors.Default
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True '// needed to get the keys.Focus.
End Sub
End Class
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
If e.KeyCode = Keys.Up Then Me.Cursor = Cursors.Default
If filterKeys Then If e.KeyCode = Keys.Up Then Me.Cursor = Cursors.WaitCursor
'// note: did not test.
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
>>Can you go through the process of making a custom cursor?
Drawing it? Cropping it? Adding colors to it? Or switching the cursor to a custom.cursor?
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
>>But where is the code for my custom cursor that I want to show?
See if this helps. :)
If you need further help, do let me know. I might find another search.engine other than " LMGTFY ".
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True '// needed to get the keys.Focus.
End Sub
In my version of Visual Studio (2010) you can't use Me.KeyPreview which is why I suggested setting it at design time and using a user defined boolean.
If you have the following at the top of your Class
Dim mycursors() As Cursor = {Cursors.AppStarting, Cursors.Arrow, Cursors.Cross}
Dim cursorindex As Integer = -1
Then in your KeyUp handler you can do
If filterkeys Then
cursorindex = (cursorindex + 1) Mod (UBound(mycursors) + 1)
Cursor = mycursors(cursorindex)
End If
For the sake of simplicity (also because I am lazy) I only included three of the built-in cursor types. You can add to the list and the code will still work. Note that the code in the KeyUp handler cycles through all cursors in the array, mycursors. The Mod function sets the index back to zero if it points past the end of the array.
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
Sorry about that. A clearer bit of code would be
Imports System.Windows.Forms
Public Class Form1
Private filterkeys As Boolean = False
Private mycursors() As Cursor = {Cursors.AppStarting, Cursors.Arrow, Cursors.Cross}
Private cursorindex As Integer = -1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
filterkeys = True
End Sub
Private Sub Form1_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If filterkeys And e.KeyCode = Keys.Up Then
cursorindex = (cursorindex + 1) Mod (UBound(mycursors) + 1)
Cursor = mycursors(cursorindex)
End If
End Sub
End Class
Don't confuse Form1_KeyUp with Keys.Up. "KeyUp" in the function name refers to the event "when a key is released (the UP event)" with "Keys.Up" which refers to the key code for the UP key.
PS - I've been programming for years but there are many many people here who are more adept than I am in VB and object oriented programming so when I suggest a solution keep in mind that it is "a" solution, not necessarily the best or only solution ;-)
Reverend Jim
Posting Shark
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159