Winforms - discard unwanted double click - c#

In my C# Winforms application I have a 'Welcome' window with a number of buttons. One of these is 'Exit' which closes the application. Other buttons replace the window with a task-specific window. All the task Windows have a 'Close' button which returns to the Welcome screen. Conventionally, the Close button is in the same place as the Exit button in the Welcome window.
The problem I have is that some users are trigger happy and double click on the Close buttons. The first click triggers the Close action, and the task window closes. But it would appear that the second click is being bufferred, and is given to the Welcome window once it is displayed, and results in the Exit button being clicked. This is NOT the desired behaviour!
Is there any way I can discard the unwanted second click on the Close button? The task windows raise an AppletClosing event back to the Welcome window when they are closing, so it would be easy to do it in that handler - if I knew what to do.
Thanks for any help - much appreciated.
Kevin

Related

Update (redraw) system-tray window after a button is removed [duplicate]

This question already has answers here:
Tray icon does not disappear on killing process
(8 answers)
Closed 9 months ago.
After I send a TB_DELETEBUTTON message to delete a button (of a external application) in the system-tray toolbar, it remains a blank/empty rectangle from that deleted button, and the toolbar does not remove this empty rectangle until I do left or right click on some other icon, then finally the toolbar window gets redrawn and the empty rectangle from he button that I deleted disappears.
This is an aesthetic issue that I would like to avoid. I just would like to programatically update/redraw the toolbar window after I send the TB_DELETEBUTTON message, however after I call the UpdateWindow, UpdateLayeredWindow or RedrawWindow, the empty rectangle of the deleted button remains there.
The flags cobmination that I tried to use with RedrawWindow are: RDW_FRAME, RDW_ALLCHILDREN, RDW_UPDATENOW and RDW_INVALIDATE, all together.
The window handle that I'm passing to these functions is the window with class name: "ToolbarWindow32" (on which reside the system-tray buttons/icons of the applications), a example for getting this window handle can be found here.
My question is: how can I properly update/redraw this window?.
After calling the InvalidateRect function I noticed that the notification area window is redrawn (because the window flicks for a moment), so redrawing the window seems not a valid solution to solve this issue...
However, in the next thread I found a solution:
https://forum.lazarus.freepascal.org/index.php?topic=14847.0
The thing is that in order to "properly" refresh the size of the notification area to remove any empty space from previously deleted buttons, I just need to send WM_LBUTTONDOWN and WM_LBUTTONUP messages through the SendMessage function.
These window messages must be sent two times (at least for Windows 10) to the ToolbarWindow32 window following the next order: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDOWN, WM_LBUTTONUP. This is to reproduce two single clicks (not a double click) in the first button inside the system-tray, which is what I manually needed to do before applying this automated solution. After sending the messages, the window becomes "auto-sized" properly.
The only aesthetic problem would be if the first button is a button from an application that performs some undesired action when doing a single click on its button, but this is not typical to see. Typically the user only can do a double-click to restore the window from the button on system-tray, or do right click to open its context menu, but nothing should happens for doing a single click on a button... if the developer didn't programmed anything to happen.
Note that this methodology also works when there is the up arrow that contains "hidden" buttons.

button hide unhide in c# console application

At the start of the application, a form must appear with two buttons on it. On the top button, the text “Button 1” must be written and on the bottom button the text “Button 2” must be written. The two buttons must be perfectly center aligned (both horizontally and vertically) in the client area of the form.
For the first time, when any of the button 1 or button 2 is clicked then it will disappear and the other button will stay unchanged. For example, user clicks button 1 for the first time then button 1 will disappear. Button 2 will be unchanged. Now there is only one button on the window that is button 2. On clicking button 2 it will disappear and button 1 will reappear on the window. Now if the user clicks button 1 then it will disappear again and button 2 will reappear. This process may go on indefinitely until the application is terminated by clicking the close button (on the top right corner of the window).
not sure what you are asking for.. but i interpret it as you need a code to make your button visible/not visible
button.visible=true;
button.visible=false;
Look
1- Inside the Event handler of each button just do:
2- change the visible property of the current button to false to hide it.
3- Check if the other button is hidden then make it visible again.
Button1.visible = !Button1.visible;
if (!Button2.visible)
{
Button2.visible= true;
}
PS. that code as a logic and info not i didn't mean a specific programming language.
is it what you search for?

Focus lost when IPleaseWaitService is called before a modal dialog using Catel

In summary, I do have a modal dialog in Catel, invoked with:
_uiVisualizerService.ShowDialog(viewModel)
Inside that dialog, I do a long process showing a Wait Service:
_pleasewaitservice.Show();
// HARD WORK here
_pleasewaitservice.Hide();
And Then I invoke another modal dialog.
_uiVisualizerService.ShowDialog(configureViewModel)
However, when I click outside of the application while it is doing the hard work (when the pleasewaitservice is shown), the second modal dialog is displayed behind the main application, so I cannot focus the Window because it is behind and it is modal. I have to close the app from the task killer.
After checking it carefully, I realized that origin is the pleaseWaitService. If I don't show it, the second modal dialog is always displayed correctly.
Does anyone have any hint about how to solve it?
I was googling about how to force to set focus in any Window, but I didn't find anything.
Thanks
Regards
Saul Hidalgo.
You might want to try the BringWindowToTop extension method inside the code-behind of the window:
https://github.com/Catel/Catel/blob/46fcc69575e533eb9e02669ebaa2246894dc98d8/src/Catel.MVVM/Catel.MVVM.Shared/Windows/Extensions/WindowExtensions.cs#L237

Close Modal Form when mouse click outside form area

I would like to close a modal form when the user clicks outside (anywhere on the computer desktop) the modal form. How can we do this as a modal form is not meant to lose focus.
You need to hook mouse (and keyboard if required) and capture their events. Then check if the click happened outside the form (and area). If yes, flag a sign which can be read by the model form that it can close down.
Algo:
Hook mouse click event.
When callback function is called, check for the click position - if it's inside your form or not (you might need to translate the locations to Desktop locations - I hope you know how to!)
If the point is outside the form, set a flag (boolean or anything that makes you happy). Make sure the form can read the flag somehow.
Trigger an event for form to capture. In it's handler read the flag status. If true, close/unload the form.
This page will tell you technical details and functions.
I don't think you need to make it modal... then you can take siride's option of closing it on the Deactivate event.
The reason you don't need to make it modal: The first time you display it, it will have the focus and be topmost. Modal prevents you from clicking somewhere else, but you want to be able to click somewhere else... and when you do, the form goes away, so there are no modal needs.

In WPF, Drag from one window and drop on another window's context menu alert dialog gets open. This alert dialog gets hang until we move cursor

In my wpf application, i try to drag the textblock from one window say (call screen) and drop it on another window say (contact window). now drop the text block on contact window's datagrid's context menu which gets opwn when drag enter event fires and as soon as the drop event fires on context menu then alert dialog (that is show dialog window with ok and cancel buttn) will gets open. This alert dialog gets hang means i can't be able tap on ok button of this alert dialog until i move my cursor around ok button.
Help is highly appreciated..!

Categories