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..:)

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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
Re: set shortcut 80 80

Handles txtsanc_date.TextChanged
should be
Handles txtsanc_date.KeyPress

Re: set shortcut 80 80

KeyPress

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

Re: set shortcut 80 80

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 ,

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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
Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

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
Re: set shortcut 80 80

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

Re: set shortcut 80 80

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

Re: set shortcut 80 80

Please mark thread as solved.. :)

Be a part of the DaniWeb community

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