User control doesn't react when I pressed a tab button - c#

I have a windows application: a main form and several user controls on it.
Tab button doesn't work as I expected. I thought it goes through all user controls on form. But I was wrong. When user control received focus (using mouse click) it didn't want to go anyway using tab button. What thing can be wrong ? Did I miss something ?
I didn't override ProcessCmdKey and other key_down events. All user controls have TabStop property = true.
C#, .net 2.0, WinForms

you can use "Tab Order" tool in "Layout" toolbar to see the current TabIndex values. make sure TabIndex is correct (starts from 0) including tabIndex in the actual UserControl as well. quickly tried on mine and seems to work. Do u have any binding setup to these controls

Related

How to determine if User Control is shown or not on WinForms

I have a windows forms application and added a menu to maneuver between few User Controls. I am using the events: Click, MouseEnter and MouseLeave.
In every event I am changing the BackgroudImage and what i want to achieve is that when the image did change after the click event, the image will stay. And I was thinking using the User Control properties to determine if he is Shown or not (as I am using the Show() and Hide() methods).
Tried using the Visible, Focused and Enabled properties but none of them changing after hiding or showing the User Control.
How can i determine if the User Control is shown or not?
The property IsHandleCreated gets true when the control is loaded. Try to use this property.
reference document :https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.ishandlecreated?view=netframework-4.7.2
Apparently when the form loaded, the default Visible property is set to True even though I really don’t see all of the User Controls (they are one on each other).
So I added a show and hide method in the form load event and the visible property works like a Charm.
Thank Franck

KeyPress at form level with controls

I am wondering if it is possible to handles KeyPress event at form level when there are controls in a form.
I can achieve this when there is no control on the form, but when i add something, like a button, the form loses the focus and i can't give it back, even with Me.Focus. The focus stays on the button.
Is there a way to do it ? If not, i would like to know why. Looks interesting.
Just set true to key preview property of your form it will work.
You can do it by enabling KeyPrivew Property of your form.

How to know when user has a text entry control focused in other applications

The purpose is for an on screen keyboard, I would like to know if the user has focused (clicked on or tabbed into) a control that allows text input so the keyboard can optionally automatically popup. I assume there is a windows message that I hook that gives me hWind of active controls when focus changes, then perhaps there is another pinvoke that alows me to check for control type based on hWind?, unfortunately thats the extent of my knowledge on the subject.
You can get just the event when something got the focus with the GotFocus event: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx
You can apply it to all Forms.

How to avoid losing the input focus on an HTML element inside a WebView?

I'm currently trying to build a touch keyboard to be used with an UWP app. One of the solutions I came up with was to use a brokered component to call SendKeys funcitons with buttons (IsTabStop being set to false and ClickMode to Press to prevent any loss of focus from the input controls). So far, everything works (tested it on TextBoxes without any trouble).
The problem: I'm encountering some issues using the WebView control : when I click a button, the WebView keeps the focus, as expected; however, the DOM elements (such as HTML's <input> markup) lose the input focus (while still being visually selected).
I found a way to solve this by resetting the focus on the webview; but that uncovered another issue. Let's say the input element is set to select all of it's content (the string) whenever it is focused. Then, each time I click one of my buttons, the content is selected and replaced by the new letter I sent to the WebView.
So, my question is, is there any way to avoid losing the focus of the DOM object when clicking on a XAML button?
NB : I do know about the InputPane, but I can't use it for this app (due to some restrictions on the client side). Also, let me know if something is unclear, and I'll edit asap.
NB2 : I have absolutely no access to the source code of the pages that will be displayed by the WebView, nor can I rely on the presence of a specific element.
The Anniversary Update introduced a new property FrameworkElement.AllowFocusOnInteraction for this scenario. Set it to false on your Button and the Button won't take the focus when it is clicked. The focus will stay on the WebView and the selection shouldn't get cleared (if not there's something else going on as well).
Prior to this there wasn't a good solution. The least bad I've seen was to call WebView.Focus() in the Button.Click handler to return the focus, then wait for the focus events to complete before proceeding in the Click hander.
If you need to target earlier systems than the Anniversary Update then you'll need to set AllowFocusOnInteraction from code after checking that it exists with ApiInformation.IsPropertyPresent . You can't do this directly in Xaml, but you can wrap the check in an attached property which can be called from Xaml. See my blog entry ComboBox on a Flyout attached to an AppBarButton loses mouse input on 1607 for sample code.

How to cancel Validation when switching TabPages

I'm writing an application in c# .NET 4.0. I've implemented TDI using TabControl and TabPages. On each TabPage there is a bunch of TextBoxes, ComboBoxes, Grids, Checkboxes etc. Each control has Validation and Validated event attached. Form, TabControl and each Tabpage have CausesValidation set to false. On each TabPage there are also some Panels, each has CausesValidation also set to false. Other controls (TextBoxes, CheckBoxes) have CausesValidation set to true. In this way, I'm able to switch between TabPages independently. However, when on one Tab, some control fails validation, controls on the rest of TabPages are prevent to receive focus. I've implemented onSelecting and onDeselecting events for each TabPage, so one way is to switch off CausesValidation on controls on TabPage, which is going to be hidden, and switch on CausesValidation on all controls on TabPage which is now in the front. Is there a better way to achieve this functionality?
Added:
I want validation to take place for each tab independently. Result of validation of one tab should not affect behaviour of other tabs. Changing AutoValidate property to EnableAllowFocusChange doesn't work - I still want to prevent changing focus if validation fails, but it should be limited only to this particular tab. If control is going to lost focus as a result of switching to the other tab, it should be allowed.
It is hard to provide source code, but here is a sample project that explains the problem.
http://www.speedyshare.com/T49DR/SampleProject.zip

Categories