wpf textbox focus issue - c#

I have a control with several textbox controls on it.
Now, when I press tab after I edit one of the textboxes, the focus is switched to the next textbox BUT I need to press an additional tab in order for it to enter the "editing" stage.
The first tab simply draws a dotted background on the textbox ... and the second one actually puts the cursor position inside the textbox. Is there a way when I press tab, to automatically set the cursor inside the textbox?
Thanks./

Are you sure you don't have any hidden controls or other controls that might be accepting focus before your textbox? Either way, you should be able to update the tabindex value of your controls so they follow a logical sequence when tab is pressed.

Related

WPF Keep textbox focussed while pressing tab key

I am writing a WPF application where we are supposed to shift focus from one button to another by pressing the TAB key.
All is fine, but for a specific page, there is a textbox which is always focused so that the user can type in it immediately. But now, when I press TAB, the focus is shifted to the button (which is as per requirement) but as the focus is lost from the textbox, I cannot type anymore.
I want to have a behavior where I can keep the Keyboard focus on textbox but should be able to control the buttons using TAB key as well. In a way, I need to have focus on textbox and the buttons at the same time. Is this possible?
Tried the FocusManager.IsFocusScope = "true", but this did not help.

Radio buttons Navigation by KeyBoard

I have 3 radio buttons on my WinForm.
I would like to give the user the option to navigate between them also by keyboard.
Is there a way to enable it?
I understand I have to use this code:
if (e.KeyChar==Convert.ToChar(Keys.Down))
But how do I know which single radio button I have to set as checked?
The simplest solution is to use keyboard shortcuts. This entails prefixing one character in each RadioButton's text with the & character.
For example if the text of your radio button is "&Big option" then the user can select this option by pressing the [ALT] and B keys at the same time.
Additionally, once one of the radio buttons has the focus you can navigate between them by using the up and down arrows. In general, the user can navigate between controls by using the [Tab] key. In VS 2010 the tab order may be modified by selecting the View->Tab Order menu item.
The same keyboard shortcut trick works for many other controls. For example if you have a TextBox control preceded by a label control you can prefix a letter in the Label control with &. Now since the Label (by default) can't take the focus, when the user uses the Label's keyboard shortcut, the focus will move to the next control in the Tab Order i.e. the TextBox.
If you want a control to be skipped when using the [Tab] key set its TabStop property to False.

How to add a button to the upper left corner of TabControl?

I have a C# 2.0 WinForms application, looks like this
How to add a button to the upper left corner of TabControl, looks like this?
I am very grateful for your help.
As Kieren Johnstone said it's not possible without creating your own version.. But you could actually just add a tab to the control and catch the on tab changed event. Get the currentTab and if it matches the one that should be your button execute said code.. Then change back to the previous tab.... Its more than possible just a little different.
If you hide the tab it will shift the entire tab control to the left effectively taking out the space you are trying to achieve.. If you do it like what I am saying. And simply add a tab to the tab control. Then use that tab as your button, It will work just like a button does just a little code behind is required to first get the event when the user clicks a tab in the tabControl.
First set the current tab index to the one you want the user to be defaulted to. Store the index value in a variable. Now catch the tabchanged event. If the first tab is selected then the user has clicked your intended button thus meaning you should fire your code that you would have fired from an actual button. Next change the selectedTabIndex to the value contained in the index variable you set earlier. If the first tab is not selected update the value of the index variable set earlier.. This is the simplest way around your problem that I can think of off hand.

C# WinForm press tabs and it jumps all over the place

I have a WinForm program. In one screen it has several ComboBoxes, TextBoxes, and Buttons. How can I make it so that when the user presses tab, it will go through the fields in sequential order. Meaning from top to bottom? Or we can say "In my defined order"? So, for example, it starts with TextBox1, and then when the user presses Tab, it will go to the next TextBox, and when Tab is pressed again, will go to Button1, etc. etc.
Not sure if it’s possible, but for some reason pressing tab jumps all over the place. What defines the "tab"? what logic does it use to make it jump to the next field?
The TabIndex property of each control defines the tab order within a container (Form, GroupBox, Panel, etc). If you are working in the Visual Studio Designer, you can use the View --> Tab Order menu item to view/edit the tab sequence.
Each control has a property called TabIndex. When a user presses the Tab key, Windows cycles through each control in the order of the tab index. If two controls have the same TabIndex, they are selected in the order in which the controls were added to the Forms Controls collection.
It is also worth noting that if you have a control that can contain a group of controls within it's Controls collection (i.e. GroupBox), the tab processing engine will give tab focus to the parent control and then cycle through all of the internal controls, in their internal sorted order. This means that all child TabIndex values can be maintained independently of all other controls that are in the same collection as the parent control.
You need to use the TabIndex propert on the control. Be aware that according to the documentation, you must set the TabStop property to true in order for it to be included in the tab ordering.
You need to define the TabIndex of each control. There is a button in the designer toolbar to make it easier (I don't remember the name, but you should find it easily... it's probably something like "Tab Order"). Click this button, then click each control on the form in turn.
Each control has a property called "TabIndex". These will by default just be incrementing as you create items. You can set these manually.
Set the TabIndex: http://msdn.microsoft.com/en-us/library/aa984423%28v=vs.71%29.aspx
Please check out TabIndex property.

Buttons Are Automatically Selected (how to turn this off?)

I have winform buttons that when you load the form, a certain button is selected. What I mean by selected, is that if "enter" is pressed, the button is pressed.
How can I change my buttons so they don't do this anymore?
Your tab order is set in the order in which you add controls on the form. If your first control which can be pressed/selected/edited is that button which is getting pressed, the focus will automatically be on it when form is loaded.
You can cheat by setting the focus to some other control (maybe which is not visible? !hint * hint!) to avoid the button to be selected at first.
But also make sure tht button is not the AcceptButton of the form.
Two concepts have been touched on by Nayan and rerun:
1) AcceptButton
2) Tab order
There is one more I would add and then try to explain how the three things relate:
3) Focus
Focus means that a child control has the "keyboard focus". When a control has focus, it receives keyboard input and can respond to it. Focus is changed either by clicking a control with the mouse, or by using the Tab key.
Tab order is the order in which controls receive focus when the Tab key is pressed. It also determains which control initially gets focus (the first one in tab order).
The AcceptButton concept is a bit of a hybred. If a form's AcceptButton property is set to a button control, that button is pressed when the user presses the Enter key while focus is on any control that does not process the enter key itself. Typically the 'Ok' button on a form is set as the AcceptButton so that the user can enter data and press Enter as a shortcut to pressing the Ok button.
You need to set the acceptbutton on the form.
Element.Select() is what worked for me.

Categories