Window Menu "Selection" Event in C# - c#

Is there an event that fires on a mdi child form when said form is selected in the "Window" menu of an mdi parent? I tried just detecting focus but I need to be able to know when the menu item is clicked even if the child window to which it corresponds is minimized.

You can try the Activated event. It fired when the form is on top

Related

How do I click the cross button (the cancel button) on the sub form and go to the main form?

I know how to close a sub form and go to main form by clicking "close" button under file menu bar, but I don't know how to cancel a subform and go to main form by clicking the cross button --"cancel" which is located on the upper right corner.
and then back to the main form
Update:
I have tried go to form property, under Event,there is an item called, FormClosing, write a click event funcation name,i.e cancel_Click, and then press enter. Then I can write code under cancel_click, but it rises another problem. Since I want use same code here as the one under "close" on the menu (both can redirect back to the main form), when I close on menu bar, it appears two main form. How can I fix this?
use Form.Closing event and then do what ever you want to do. link
Set the FormClosing event for the sub-form to go to the main form. Set the FormClosing event for the main form to exit the program.

Is it possible to drag something from a dialog window to it's parent in C#

Just as an example, say I have a form with a listbox. From this form I open a dialog window using dialog.ShowDialog(this), which has another listbox. Normally, the user would double-click items in the dialog's listbox to add it to the owner form's listbox, then close the dialog when they are done. I want to know if I could enable drag and drop so the user could instead drag an item from the dialog's listbox to the owner form's listbox. From what I can tell, at least on my Windows 7 computer (using .Net Framework 4.0), this is not possible.
An additional feature I'd like, but is not necessary, is if the owner form could be brought in front of the dialog window while user is dragging item over owner form. (This is to enable the user to better see the listbox on the owner form while dragging.)
I dont think this is possible, more accurately not advisable. Clarify if I am wrong. What you are trying to do is drag an item from a modal that appears super-imposed on the form ( Instead of double-clicking and bubbling the data back up to the parent). In order to achieve a drag and drop, somehow you will have to, upon clicking to drag, trigger a loss of focus on the modal, and then drop, after which you want to regain focus on the modal. To me this seems like a circuitous way of going about a minor quality of life improvement.
This can be done by having the owner form handle the drag event directly rather than having the child control on the form handle the drag event. Set AllowDrop = true and handle DragDrop and DragOver events for the form. You can use control.ClientRectangle.Contains(control.PointToClient(new Point(e.X, e.Y))) in the form's drag events to determine if the mouse is in the desired control's client region.
You cannot bring the owner window in front of the dialog (and probably shouldn't try), but the user can easily move the dialog out of their way if necessary before beginning the drag.
Note: You may want to add if (!this.CanFocus) e.Effect = DragDropEffects.None; to your form's DragOver event to disable drag events while dialog is being shown, unless the drag is from the dialog window.

wpf mvvm how to cancel click event

I have two windows: parent and child. I'm opening and closing child window by clicking button "Open window". Child window closes on lose_focus event. But when child window is opened, I click on "Open window" child window loses focus, closes, then button_click event raises and child window reopens. I whant to cancel button_click event if focus_lost event was raised before it. How can i do this?

C# detect when form becomes unfocused?

Is there a winforms event that fires when the user switches from a form to another window? I.e. Not through minimizing, but just by clicking on another window. How can I detect when the form becomes inactive? Thanks!
Form.Deactivate

C# MDI Parent Gain Focus by clicking on MDI Parent background

I want to set focus to an MDI Parent Form when I click on the background of the form. However, the only way I can get it to set focus is when I resize the form.
I have tried using mouse click event, click event, key press event etc to manually set the focus when you click on the MDI Parent but none of these events fire. Is there ANY way to set the focus to the MDI Parent when you click on the background of the form?
That background is a separate control, try to find it in MainForm.Controls and assign it's click event.
You may want to look at the Win32 WM_MDIACTIVATE message. Now that we've discussed a possible solution, the real question can begin:
I think you should look long and hard at what your trying to accomplish. You risk (not necessarily will, but risk) creating a behavior that is abnormal and confusing to users. Why do you want to move the focus? What will you once it gets moved? How will you indicate to the user that this has been done? How will then get out of this state?

Categories

Resources