Basically I'm trying to capture the TAB key for use with a barcode scanning gun that will scan the barcode then automatically enter a TAB key after the scan. Unfortunately due to other applications that are using the barcode scanner, I'm forced to deal with the TAB key. I tried using the Leave event but that event wants to fire all the time including when the control has focus and the user clicks a button or when the control has focus and the form is being closed. I've been unable to come up with a viable solution just yet. Any help would be much appreciated!
Thanks,
-Tim
9 Answers, 1 is accepted
In the case of the tab key, the windows handlers grab the tab key and move the cursor to the next control. The KeyPress event does not fire for tab when tabbing from one textbox to the next (this is the same for Windows controls too).
In order to get over this, you can override the ProcessDialogKey. Please consider the following:
'// To know when we want to capture the tab
Private
m_IsFocused
As
Boolean
AddHandler
Me
.RadTextBox1.Enter,
AddressOf
RadTextBox_Enter
AddHandler
Me
.RadTextBox1.Leave,
AddressOf
RadTextBox_Leave
Private
Sub
RadTextBox_Enter(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
m_IsFocused =
True
End
Sub
Private
Sub
RadTextBox_Leave(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
m_IsFocused =
False
End
Sub
Protected
Overrides
Function
ProcessDialogKey(
ByVal
keyData
As
Keys)
As
Boolean
If
keyData = Keys.Tab
AndAlso
m_IsFocused
Then
MessageBox.Show(
"Tab Pressed"
)
End
If
MyBase
.ProcessDialogKey(keyData)
Return
True
End
Function
Hope that helps but let me know if you need more information
Richard
Thank you for your help. Your suggestion works like a charm. I did have to change one line though. In the ProcessDialogKey function I had to Return False instead of Return True as you suggested. If I was returning True then I couldn't type anything into the text box. I didn't look up the documentation but I assume the return value is probably a "Handled" property in which case setting it to False allowed the data to be entered in the control normally. Again, just speculating but what matters most is that it works!
Thanks again!!
-Tim
Glad that I could help and that this works for you.
All the best
Richard
Thank you for writing.
The behavior you experience is a known issue and has been logged to our Public Issue Tracker under ID 9505. It was resolved in Q1 2012 SP1 (version 2012.1.321).
I would like to point out that you should not set the TabStop property of RadTextBox to true. If you look carefully at the architecture of the control, you will see that it contains a HostedTextBoxItem that actually holds the focus.
I hope my answer helps. Let me know if you have further questions.
Regards,
Boryana
the Telerik team
Hi,
currently I am trying to capture key stroke combinations within the ProcessDialogKey, like Ctrl+A or Alt+F4.
I couldn't find out anything about this. Is this even possible with this Method?
- Sidath
Hello, Sidath,
This seems to be more like a general programming question. After further research in the appropriate forums like StackOverflow and MSDN, I have found the following useful threads:
Overriding the Form's ProcessCmdKey method allows you to detect key combinations, e.g. Ctrl+A:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
public RadForm1()
{
InitializeComponent();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.A | Keys.Control) )
{
Console.WriteLine("Ctrl+A");
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Sorry I should've mention what I am trying to accomplish.
As the Telerik DateTimePicker doesn't fit my needs I built my own which inherits from RadTextBox.
I override ProcessDialogKey() to avoid dealing with anything else than numbers, dot, modifiers, esc and tab.
So with this method I only have one key registered when pressed if I'm not wrong.
Therefore I didn't come to any result with this.
With the method you provided just nothing happens.
BTW I am using Progress 12.2 for coding.
- Sidath
Hello, Sidath,
According to the provided information, it is not clear why RadDateTimePicker doesn't fit your needs. Could you please give us some more details about the exact goal that you are trying to achieve and how RadDateTimePicker affects this requirement? Once, we get better understanding of the precise case, it would be able to think about a suitable solution and provide further assistance. Thank you in advance for your cooperation.
I have created a derivative of RadTextBox on my end and override both, the ProcessDialogKey and ProcessCmdKey methods. Both of them seems to detect pressing Ctrl+A:
public class CustomTextBox : RadTextBox
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.A | Keys.Control))
{
Console.WriteLine("ProcessCmdKey Ctrl+A");
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == (Keys.A | Keys.Control))
{
Console.WriteLine("ProcessDialogKey Ctrl+A");
}
return base.ProcessDialogKey(keyData);
}
}
Is there anything specific in the setup that you have on your end? Do I need to perform any other changes?
Off topic, please have in mind that we offer RadPopupEditor which may be suitable for your scenario. You can host any control, e.g. RadCalendar, if it is necessary, in the popup. Additional information can be found here: https://docs.telerik.com/devtools/winforms/controls/editors/popupeditor/popupeditor
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik