Good afternoon
in a project I have to intercept the shift of focus from one textbox to another any control present in the window when the left mouse button is pressed.
The problem is that once the key has been pressed I detect the receiving control while I would need to know the source control in order to be able to carry out checks on the data present and, in the event of an error, refocus on the source control.
At this moment I already have an event connected with the LOSTFOCUS on the source control but when I try to change the focus (once the data error is detected) to the offending TextBox this is not minimally detected and the focus goes to the new selected control.
I have been surfing the net since yesterday but I can't find anything that solves the problem.
Does anyone have any ideas on how I can fix the problem.
Thanks and good job
Perini Luca
Related
I have a tablepanellayout which has three child control (label, edit box, button).
I have defined access key(alt+somekey) on label.
But when i press access key focus is going to tablepanellayout then to edit box.
My goal is to move focus to edit box directly.
What I tried.
tried changing tabindex. didn't work.
thought to write focus handler for tablepanellayout and move foucs to edit control but shifttab won't work.
changed the order of adding child into tablepanellayout (label, editbox, button) no effect.
thought to change the tablepanellayout focus setting but didn't find any property whihc can do this.
How can move fouc to directly to editbox on pressing of access key and bypass focus to tablepanellayout?
EDIT: Screenshot from inpect tool
I got the solution.
As the tab is working fine only problem is with access key hence implemented gotfocus event handler which sets focus to text box.
Using c# winforms vs2008
I'm using a TabControl on a form. Each tab has a different set of input fields. Some of those fields has to be completed. Such as Username. Multiple users will use the same PC, so a the username must remain static. I have a leave event on the require fields which triggers when the textbox loses focus to check if a value was added. In the case of Username, a popup would then presents possible values. That works pretty awesome to ensure accuracy and speed. To problem comes in when the user clicks on another tab, the textbox leave event triggers. How can I prevent the leave_event code from running if the focus changes to a control not on the current Tab?
I have tried different event handlers, but the leave event seem to occur first. I tried textbox validating event handler, but also no success. I tried adding a If-statement in front of the code to check the tab number, or tabcontrol state - no joy - as before anything else changes, the leave event fires.
The only remaining thing I can think of is to loop through all the controls on the tab to check if they have focus, but that just feels messy.
Any other suggestions?
I have found a partial solution. Using a Mouse_Enter and _Leave event on the tab, I set a flag to determine whether the mouse was clicked in the form or outside. If the flag is set to false, the leave event dont run. This will not solve short cut key presses though. But that I can handle later.
I am having a problem with DateTimePicker when I show the UpDown arrows. It actually happens also with the numericUpDown control. It does not happen with the calendar.
If I click with the mouse in any field of the DateTimePicker and then click the arrows to change the value, I cannot then leave the control.
Sorry, I don't really know how to explain this properly (probably the reason why I haven't found anything about this when searching). The software does not hang but nothing works apart from the DateTimePicker; for instance, I can click with the mouse in a button and the visual effects will run but not the click event...
So, the only I can do is to force the program to close. It is like if it was just stealing the focus or the mouse click event and the keys events and not letting it go anywhere else. The tab key doesn't work either.
The dateTimepicker is bonded to a column in a datatable and there is not code into them at all.
I am sure this is something stupid that I am missing, but I am getting already frustrated with it.
Any advise please?
I have found that this only happens when the property Text of the controls with UPDown (DateTimePicker and NumericUpDown) is binded. It does not do it when the property Value is binded instead.
Although this solves the problem in my applycation, the behaviour is there and cannot find an explanation for it.
So I was asked to fix an issue with an old windows form utility that has been around a little while (least before any of my coworkers showed up). The form has a numericUpDown control that is databound. The issue was, when you clicked the up or down arrow the values would change and save OK however, if you just typed in a number and clicked save it wouldn't save. It was like the databinding never saw the change, so coming from a WPF background I guessed that changing the following
TaskDaysToComplete.DataBindings.Add("Value", taskTemplate, "DaysToComplete");
To this
TaskDaysToComplete.DataBindings.Add("Value", taskTemplate, "DaysToComplete", false, DataSourceUpdateMode.OnPropertyChanged);
would solve my problem and it did. You can now either type in a number or use the up/down arrows on the control to set the "Value" property.
My question is this, what was happening in the first place? I am guessing the default DataSourceUpdateMode was OnValidation but when does this happen and why was it OK for when using the up/down arrows but never seemed to happen when typing things in.
Thanks!
numericUD validation
validation is done on losing focus, so when you press the up/down key the textbox loses focus - triggering the validation routine.
when editing text you can make the control lose focus by clicking another control, this will cause it to validate.
the reason that the default is set to onValidate is that on value changed will cause it to validate on each character typed, which can be problematic both for performance and for correct validation.
I'm sure I'm missing something very easy here. Pretty much any internet search for a Timepicker for C#/WPF points to this webpage: http://jobijoy.blogspot.com/2007/10/time-picker-user-control.html and as such I figured it would work correctly. However, when I copy/paste this into a user control and run it, the control shows up as it should, but when I click on the digits and press Up or Down, nothing happens. Even in debug mode with a break point on the switch case for the KeyDown event, nothing happens. It's not registering the KeyDown event. It's supposed to focus on the grid that contains the TextBlock, so I tried changing the KeyDown to the TextBlock, but to no avail. I cannot seem to get this to work! :( I'm using Visual Studio 2008.
There is an official Microsoft DateTimePicker control included in the WPF Toolkit. This will be part of the framework in .NET 4.0
I think you're the control is not getting focused, for some reason. I tried it, too, and the event wouldn't fire for me, either. This post might offer some insight. Manually setting focus to the user control in the Loaded event didn't work for me, though.
The only thing that did work for me was doing all of the following:
changing the TextBlock to a TextBox and moving the event there (focus is pretty evident with a TextBox)
changing the cast in the event to FrameworkElement (which is where the Name property comes from) instead of Grid
changing the case to the TextBox's name (instead of the grid's name)
changing the event to a PreviewKeyDown (to get the cursor keys to register)
Of course, this only got the event to fire and register properly, the values don't seem to show up (even before I changed the code), but it handles the specific issue of the event not firing.
There's a DatePicker and a TimePicker in silverlight 4
If you want you can create your own control with those or simply use each one separated.