WinForms: can a menu click handler determine which edit control on the form had focus immediately preceding the click? - winforms

WinForms.
Let's say we have a grid on the form with some cell editors (checkboxes, radio button groups). The form has a file menu. File -> Save. User visits a few cells in the grid, and clicks a checkbox in a cell, and, without touching anything else with the mouse and without touching the Tab key, clicks on the File menu and then clicks Save.
Inside the Save menuitem click handler, is it possible to determine which checkbox in the grid had focus immediately prior? That checkbox won't have lostfocus yet because a menu choice doesn't cause its lostfocus event to fire.

Related

WPF How to prevent interaction with controls in background when Popup is open

When I display a Popup all other controls in the background appears to be not active (i.e. when I hover over a button for example it does not change a style). When I click somewhere to dismiss the Popup and it just happens to be a button where I clicked, that button takes a hit. This is very confusing, because one would assume that they can click anywhere to dismiss the popup and not just the empty space.
How to prevent interaction with controls in background when Popup is open?
OR
How to make controls in background react to the mouse hover even when Popup is open (like ToolTip)?
Setting IsHitTestVisible either to true or false seems to have no effect.

How can I prevent events being fired on the Winform when I click on a WPF popup?

I have a wondows form which contains a WPF control as well. When I click on the control it brings up a WPF popup control with a listbox. The goal is, when I select an item on the listbox, the windows form will be repopulated accordingly and the popup should get closed. The current implementation with SelectionChanged on the listbox works fine.
Here is the problem. The popup is big and covers some portion of the winform which contains some links. Now, when I select an item on the listbox, the popup closes after doing necessary actions, but if there is a link just below the popup (on the winform) that is under the cursor (when you selected the item on the listbox), that link is also taking the click event.
Is there any way to prevent the links getting clicked when I click on the popup? I have to close the popup though.
I think I figured this out.
SelectionChanged gets executed when we press the mouse key down and before we lift it.(Mouse key up). The popup gets closed in SelectionChanged before we lift the Mouse key. So, when we leave the mouse key, the keyUp event actually gets fired for a link on the Winform as the popup has been closed by now.
I moved the logic from SelectionChanged to PreviewMouseUp and the popup stays till I leave the mouse key and therefore the links on the Winform do not get the event. Of course, I check whether the selection has been changed or not.

How to detect a click on the selected row of a RadGridView control

My WPF application uses the Telerik RadGridView control on a few of its screens. I have a requirement that says that whenever the user clicks on a row in the RadGridView, I'm supposed to switch to another screen and display detail information about that row. I hooked up a handler to the SelectionChanged event and this works, except that nothing happens if the user clicks on the selected row a second time. This makes sense, as the selected row isn't being changed.
How can I detect a second click on the same row and have the second screen displayed?
Tony
You could just attach a handler to the MouseUp event on the GridView. Check if there are any selected cells and respond from there. This will fire even if there is already a selection.
The MouseDown event will fire on the mouse click, but before the gridview updates the selction, mouse up should fire when the selection has already been adjusted
You can also attach a handler to each individual cell in code-behind as follows
(this.GridView as RadGridView).AddHandler(
GridViewCell.MouseUpEvent,
new EventHandler<Telerik.Windows.RadRoutedEventArgs>(this.OnMouseUp));
I think you may try to achieve this through the MouseLeftButtonDown event or PreviewMouseLeftButtonDown event.

Buttons keeping their focus class after losing focus

I have some buttons in a bottom toolbar of a gridpanel that control adding, and removing records from the row-editing grid.
The handlers are pretty simple: "new" button creates an instance of the model, appends to the grid and then opens a row-editor on the new row; "edit" button just opens the selected row's row-editor; "remove" destroys the record from the store and refreshes the grid view.
For some reason these buttons don't lose the focus class that gives them a border when they have the focus. Here is a picture:
In the picture both the "New" button and the "Remove" button have the focus class, when I press the "Edit" button it also keeps the focus classes even after doing a complete row-edit operation and closing the row-editor.
I did find that when I mousedown on one of these permanently "focused" buttons and then mouseup away from it and then click something else the focus class goes away.
I know that I could put a blur handler for all button components in my respective controllers but I would have thought that this functionality was built in so I am asking to see if there is something I missed somewhere in the docs.
The classes that it won't let go of are these:
x-focus x-btn-focus x-btn-default-toolbar-small-focus
This is with ExtJS 4.1.0 in FF10 on Windows 7. But I did notice similar behavior in ExtJS 4.02 and 4.07, just haven't needed to handle it until now.
I found out what it was:
At some point in the handler chain for each of these buttons the button gets disabled. When a button is disabled in ExtJS it prevents the blur event from firing.
It was necessary to disable the buttons so the solution to simply add button.blur() in the handler was the correct way to do go about it.

How can I float buttons on top of controls when the mouse enters (WPF)?

I want to make a control which will work like the tab header in Visual Studio 2010.
When you have a few tabs open (MainWindow.xaml, MainWindow.xaml.cs, etc.) only the active tab has a close button visible, but when you hover the mouse over an inactive tab the close button appears, which means you can close any tab with one click.
It probably will be a border with text under the floated buttons.
All WPF controls are containers, you can put a button inside a button for example. You can have a layout manager to a control with the items you want in it.
For what you are asking about you could have a user control that has a TextArea and a Button in a StackPanel. Then hide the button. You then have the user control register for its MouseEnter and MouseLeave events and when the mouse is over you make the button visible, and when it leaves you hide it again.

Resources