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

Error: 'keychar' is not a member of 'System.EventArgs'

You have to use it in the Keypress Event. Or else it won't work.

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

Handles txtsanc_date.TextChanged
should be
Handles txtsanc_date.KeyPress

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 ,

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

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.

or you could also try instead of using "Chr" use "ChrW".

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??

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

Please mark thread as solved.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.