how do I set a shortcut key for 1 of the textboxes in vb.net.
When I goto the textbox and press F3, then it should give the current date in the textfield...Can somebody help me with this??
Thanks in advance..:)

shortcut key ? please explain little bit . and as i understand your question you can do like this.

' use this code on the textbox keypress event 
if e.keychar = chr(keys.f3)
 textbox1.text = now().tostring
end if

hope this will help you.

Regards

K, this is what I tried....but still doesn't work...

Private Sub txtsanc_date__KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtsanc_date.TextChanged
    If e.keychar = Chr(Keys.F3) Then
        txtsanc_date.Text = Date.Today.ToShortDateString

    End If

End Sub

KeyPress

@daniel955
I made the above changes, but still not working!!

please use this code , it is working fine at my end.

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            TextBox1.Text = Now().Date.ToShortDateString
        End If
    End Sub

this code is not working with f3 or any function key ,

Edited 4 Years Ago by M.Waqas Aslam

Thanks, it works but then is there any specific reason why not for F3 key??

Edited 4 Years Ago by prancode

The reason why I'm specifying F3 key is because if I give another date and then click on enter, the date is changed back to the current date. So that shouldn't happen...

Why cant u try like this

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.F3 Then
            MessageBox.Show(e.KeyCode.ToString)
        Else
            MessageBox.Show(Keys.KeyCode.ToString)
        End If

    End Sub

@Pgmer... y do I need to set a messagebox??? i only wanna display dat when I click f3 when in specified textbox...

I just gave as example to show Which key is pressed for testing.. You need to take only what u need.

I actually had tried replacing keys.enter by keys.F3, but then it didn't work... So wanted to know is there any specific reason as to why it wouldn't work for any of the function keys??

Edited 4 Years Ago by prancode

In keydown event my code works good for me... Why cant you try that code in keydown? Instead of messagebox you can write ur code what you want to do after user pressing F3 key...

This should work for you..

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.F3 Then
            TextBox1.Text = Now().Date.ToShortDateString()
        End If

    End Sub

Cool...It works Pgmer...:)...thanks a lot...I have been slogging for it sinc 3 days..

Cool...it works...thanks Pgmer..I was slogging for it since 3 days

This question has already been answered. Start a new discussion instead.