I have a DevExpress Callback panel with a group of buttons and a text box inside of it. When the user clicks a button, it adds the message to the textbox and performs a callback. Users can also type into the text box, and when the textbox loses focus, it also performs a callback. When the callback is occurring, a modal loading panel appears to stop users from spamming buttons to fast and jumbling the words up in the text box (I'm sure I could handle this better with my jQuery code, but I am pretty new to that, so I am doing the best I can). My main issue is that while a callback is being performed, the User can keep typing the text box, and the new text gets deleted when the callback finishes. My conclusion is that I just wanted to stop all input during the callback, so I was hoping there would be a way to disable all the controls inside of the panel during the callback, and then re-enable them when its done. I know it is possible to hide them, but that is quite the eyesore IMHO.
any ideas?
Related
The last time I did any serious programming was 25 years ago in C with a copy of Kernighan and Ritchie. Please be gentle with an aging amateur!
In essence, it's the old nullable date picker thing. I have a solution working perfectly well with one exception. I am using a combination of a masked TextBox and a MonthCalendar. The masked TextBox simply displays any value (including null) from a data set and accepts values from the calendar. Pressing backspace in the calendar clears the masked TextBox. All This is very straightforward. All I need to do now is to hide the calendar when it loses focus. A simple example demonstrates the problem I have:
Create a form with a text box to take the initial focus, a masked text box and a hidden MonthCalendar. In the Enter event of the masked text box, I have the following code:
monthCalendar1.Visible = true;
monthCalendar1.Focus();
My intention was to put the following code into the Leave event of the MonthCalendar:
monthCalendar1.Visible = false;
For some reason, this code is triggered as soon as the calendar gets the focus and the calendar is hidden again immediately. Debugging confirms that this code is triggered. If the Leave event is empty, the MonthCalendar does indeed get the focus and retains it, because it is possible to navigate the calendar with the arrow keys.
Can anyone explain this behavior to an old fogey or, even better, give me a pointer to what I'm trying to do.
Many thanks in advance.
A work around is to delay the focus of the MonthCalendar control until after the Enter event is finished firing:
monthCalendar1.Visible = true;
this.BeginInvoke(new Action(() => { monthCalendar1.Select(); }));
Quote:
Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http://msdn.microsoft.com/library.
From MSDN. They also talk about which events happen when you get in depending on how you get in :)
I am working with a TextBox, and need to fire some logic when the textbox has lost focus.
My problem is twofold:
The Leave event is firing on every keypress for some reason, meaning the logic is run with every keypress when it should not.
When using the Focused property of the Textbox as a double-check, simply exiting out if the property is still set, it now works when the user uses the mouse to leave, but not when the user tabs out.
The Focused property of the TextBox in question is False as of when its Leave event fires when the mouse is used to change focus, but it is still True when the Leave event fires due to a Tab keypress. Seriously?
I need a workaround, because the logic firing on every keystroke is causing a problem for users right now that needs to be fixed post-haste.
I created a form with a textbox on it and attached event handler to the leave event of that text box. I then typed a bunch of stuff into said textbox. The event was not raised. I hit tab, the event was raised. I then clicked back in the textbox, typed some more, and then clicked another control and the event was raised.
I'm just saying that something else is interfering with the textbox. I would look into that a little more, or post some code demonstrating the problem.
I have a form that requires a long operation (expansion of a treeview node searches the network for additional items to create more tree nodes) - so I plan on using a BackgroundWorker for this task. During the long operation I want the cursor to be the wait cursor and I want the entire form to be unclickable except for the Cancel button. I know I could use Enabled=false but this turns the treeview grey which looks pretty lame imo.
I could just NOT use a BW but that means I have to use DoEvents to get the cursor to change and that possibly "Not Responding" would show up, which I hate.
I thought of handling all the mouse click events and keyboard events so that they are cancelled if the BW is busy... so that is my current plan. I just wondered if I am missing something, if there is another way.
Thanks.
There is no easy way to do that. It is better to fix your treeview and use Enabled property. You can also show your progressbar in Modal dialog - that will block UI
You could use a Panel as an overlay over the form, wholly or partly transparent, which only propagates clicks when over the cancel button - similar to the way browsers simulate modal windows by 'graying' the background with an overlay.
When you are in processing mode, set the Z-Order of the mask to be in front of all other controls, and when that finishes set it behind them.
You could use Background worker and pop up another dialog with progressbar and that shows current progress and a cancel button. Where you can user
popup = new ProgressWindow();
popup.Owner=this;
popup.show();
And the cancel button will cancel the background worker. In this way your back form will not be clickable and popup will remain on top with cancel button.
I would like to remove the original event behavior of controls within a form (similar to design mode).
So, when the user clicks on the button, i only want to capture that event. I do not want the original button event to be fired. Is this somehow possible?
I am looking for a generic solution. So it should work with any form and any control within the form.
Reason: I wrote a form validation rules designer. It uses reflection to enumerate all form-types in the entry assembly. The user can then select a form type, the designer creates that form, enumerates the controls, and embedds the form in the designer panel.
clicking on a control, opens a formular designer panel, and the user can now create a formular for that control and saves the formular to a DB.
When the form is then opened in the normal "runtime" mode, it loads its validation formulars.
Events are not in fact disabled in the Winforms designer. The designer executes the constructor of the form through Reflection, everything in the InitializeComponent() method executes, including the event subscriptions. Wherever this might cause a problem, the controls check the DesignMode property (prevents a Timer from starting for example) or by custom designers. The form is displayed underneath a transparent layered window on top of which the selection rectangle and drag handles are painted. Which prevents issues with mouse clicks and keyboard focus.
You probably ought to look at this magazine article to get this working for you.
From what I understand from your question, I guess, you can still use the "DesignMode" property for this as well. In your event handling routine, you may want to bypass execution by checking on this property:
if (this.DesignMode) return;
as the first statement in your event handling block of code.
I have a UI with a search text box and a button that that should be clicked when the user want to preform the search. (like a search engine UI)
I want that the same event handler will be called when the user hit the search button and when the user hit enter in the text box.
I can easily hack it but my guess is that WPF has it's own 'right' way of doing it.
So what is the WPF way of doing it right?
Thanks.
There are different delegates for click and keypressed events.
So extract your code in method
named like 'DoSearch', then connect different (mb anonymous) handlers to events and call DoSearch inside handlers