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.
Related
I have a Windows Forms application and I want to be able to show a 'post-it note' type thing when the user does a specific action.
For example: The user does something which automatically hides a control.
My application should:
o Pop up a post it note which explains what happened.
o Hide the post it note again when the user clicks anywhere on the form.
I have implemented the post it note as a simple panel with a label in it, which shows and hides when specific things happen.
However, I can't seem to capture the OnClick event of the parent UserControl. The parent control is a nested control, containing a split container, one side of which contains the panel and a tab control, each of which contains a user control with various things in it.
Apart from handling the click event of every single child control, can anyone think of an event that I can capture on the parent control that I can use to hide the post it note when the user clicks anywhere in the parent control?
Thanks,
Rik
That's what the Capture property was designed to do. Set it to true when you pop up the note. Any mouse events will now be directed to your control, even if the mouse moves outside of the window. This is also the way that, for example, the combobox dropdown list works. Keep in mind that it is only good for one click.
If the popup contains any controls itself then mouse capture isn't the solution. Make it an owned form instead and simply call Close() in an event handler for the Deactivate event.
There is bubling of events in windows form, while you click on child event, the event is raised for child, and then for parent. Unless you specify "handleEvnet" property to true. So just leave it false, untill event reaches parent.
This one is a bit tricky to explain.
I have a usercontrol with some textboxes. I also have a menu just above this usercontrol in the same window. Whenever I tab away, the LostFocus fires correctly on the textbox, and this is what I want. Strangely enough, if I click the Menu button on top of my window, the LostFocus event does not fire on the textbox. Is there an elegant way to make sure that my menu properly allows LostFocus to fire on any controls which last had focus?
I also want to avoid having to Update BindingExpressions otherwise I would likely be doing this for N textboxes, which is undesirable.
I can't imagine it is too difficult to achieve this.. I just don't understand how this doesn't work: in most other situations LostFocus always fires.
Any ideas? Thank you.
Is the menu WPF as well or Winforms / UnManaged? If either of the two then the lost focus event does not fire. This can play havoc with WPF controls as many time a save or other data function is being performed from the menu. To counter this I have had to implement multiple ways to combat this. The easiest way was to implement a mouse leave event on the user control itself and perform any actions you require manually in code.
I added the event, I click in the label and press any key, but it doest go to the method. How can I capture?
I don't think labels can receive keyboard input. It will go to the control with focus, and labels can never have focus (by default, I guess you might pull some shenanigans though), most likely your events are going to your main form.
Maybe you could disguise a text box to look like a label.
To add content beyond my other comment. Have you looked at something like input bindings for what you are trying to do?
http://msdn.microsoft.com/en-us/library/system.windows.input.inputbinding.aspx
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
I would like to set the focus on a TextBox in my custom document content in WPF. I set all those focusable parameters to true. Still, the focus is not on the TextBox. Any thought or comment ?
So far, I've added these:
textbox.Focus();
textbox.SelectAll();
to the constructor of my WPF page.
The TextBox is in a Canvas inside a DockPanel, and all of them are part of a custom:DocumentContent.
thank you in advance,
Take a look at this blog post and the MSDN Focus Overview article. From your question it sounds like you're trying to set focus in the constructor. The UI Elements have not been created at that point. You should set focus during the Loaded event of your control.
That should work. Check if textbox.Focus() is returning true, it will tell you if call did work. Also, try calling textbox.Focus() from Loaded event of Window/Page.