Combobox gets closed on MessageBox closure ZK - combobox

I'm using ZK CE-9.0.0.
I have a combobox which I need to open programmatically, on click of OK button of the Messagebox. Hence I have implemented a Listener for the click event of the OK button. Inside the click event, I'm opening the combobox by using the following code:
EventListener<Messagebox.ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
#Override
public void onEvent(ClickEvent event) throws Exception {
mycombo.open();
}
};
Messagebox.Button[] buttons = new Messagebox.Button[] {Messagebox.Button.OK};
Messagebox.show("Hi btn", buttons, clickListener);
Now the problem that I'm facing is, the combobox opens for half a second. It then immediately gets closed automatically.
As per my understanding, it's because of the Messagebox. Once the execution of the click event is completed, the Messagebox is closed & it causes the combobox also to be closed.
Please have a look at this fiddler for better understanding. Please select the ZK version to be 9.0.0 before running it.
Can anyone help me with this please?
Thanks,
RAS

You are correct that the main issue comes from the button retrieving focus after the animation of the combobox.
The focus is given back to the button by the closed messagebox
Since the combobox loose focus, the combo popup is also closed.
A clean way to handle this would be to use an echo event to wait for the messagebox to be actually closed before sending the open action to the combobox.
See this fiddle:
https://zkfiddle.org/sample/1rkm5d/6-Combobox-gets-closed-on-MessageBox-close#source-2

Related

WPF Tab_selectionChanged

I have this strange issue I am facing currently.
I have created an WPF application based on WPF page navigation. I have few button and depending on the button click the the user is navigated to respective WPF page.
In these WPF pages I have Tab controls and have used selectionchanged event handler to perform some task.
Now to the issue,
When I try to go a particular page, the selectionchanged event is also executed even before the page is loaded completely, I have tried to use the windows.loaded (based on the answer provided to my previous question - here) - I have no luck.
[I am using WPF Navigation framework]
Somehow the selectionchanged event is executing twice.
How do I stop this from happening?
I think you should check SelectionChange.AddedItems and SelectionChange.RemovedItems to find the difference between these to firings. I guess that when you select a page, SelectionChange.RemovedItems==0 while when you click on a tabItem to select it, SelectionChange.RemovedItems==1. if so just write:
if (SelectionChange.RemovedItems==0)
return;
Edit1: Please see the first comment.
Edit 2
void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count == 0)
{
// I guess this is the event that happens when a page is selected
// in this case just a TabItem is added to the selection
// and nothing is removed, so do nothing
return;
}
// if you are here, it means that this is another selection changed event
// so Perform those tasks that you mentioned in your question
}

updating UI in windows phone 7

In method that is working in the background, i have two important lines :
createPopup();
MessageBox.Show(sth);
more lines
more lines
createPopup() just creates a popup, adds a grid as a child and shows popup.
My question is, why first shows up messageBox, then shows up Popup, which appears after all lines in this method done ? How could I make this popup to show before all lines in this method will be done ?
All the UI changes are normally queued up and will be shown at once on the screen.
And this does not include MessageBox. So it shows up immediately and prevents the execution, until user clicks on Ok. Hence eventhough your popUP is first executed, it will be shown in the UI only after the MessageBox.
For your problem, Try placing your MessageBox.Show(something) in a separate thread.
createPopup();
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("some message");
});
more lines
more lines
Give it a try. I am not sure whether it solves your problem or not as I dnt know the code in createPopUp() method.
Creating the pop-up, does not actually draw it on the screen until the Layout event. If you want to ensure that the pop-up has been drawn before you display the pop-up, attach an event handler to the pop-up's LayoutUpdated event and display the message box from within that event handler. Be sure to detach the event handler as well or you will see multiple message boxes.
public InitPage()
{
Popup popup = new Popup();
popup.LayoutUpdated += popup_LayoutUpdated;
LayoutRoot.Controls.Add(popup);
}
void popup_LayoutUpdated(object sender, object e)
{
popup_LayoutUpdated -= popup_LayoutUpdated;
MessageBox.Show("hello");
}

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.

Name of closing button on Windows Forms

What's the name of the default red button with an X in the middle at the top right?
EDIT: I want to get the event associated with clicking that button.
You cannot disable the close box on its own using in properties window like you can with the minimize and maximize boxes. You can however disable the control box which contains them all.
Setting ControlBox to false will remove the minimize, maximize and close buttons.
You might want to consider why you are doing this though, as it's generally a good idea to let users quit out of windows using the close button (think of it as a cancel button).
EDIT:
You can handle when the user clicks on that close button using either the Closing or the Closed events of the Form. The difference between the two is that the Closing event fires before the form has closed (meaning that you can veto the closure by setting the Cancel property of the FormClosingEventArgs to true), whereas the Closed event fires after the form has actually closed.
it is possible to hook all messages goes to a form by implementing ImessageFilter interface
this link can be use full Using IMessageFilter to create a generic filter for operating system events
You can disable it by setting the ControlBox to false in the form properties, or in code like the following:
this.ControlBox = false;
Setting this will also hide the minimize and maximize buttons if that is OK. If not, the solution is a bit more elaborate.

Popup window and context menu

I am using the ToolStripDropDown to host the user control as the pop-up window. The problem is when a context menu strip is displayed from within this pop-up window, the pop-up itself closes in the moment the context menu opens.
I have tried to subclass the ContextMenuStrip and added WS_EX_NOACTIVATE to CreateParams but nothing changed. First I thought that there is no way to do this since it is common behavior but then I tried to put a TextBox class onto the pop-up user control and invoke the Edit control context menu - and the parent pop-up window did not close.
What am I missing?
Had a similary Problem. On my UserControll was a toolstrip. When I pressed the toolsstripdropdownbutton the dropdown was shown but the popup disapeared.
The reason was that popup.Autoclose was true. After Setting to false the Popup is not closed any more.
ToolStripDropDown popup = new ToolStripDropDown();
popup.AutoClose = false; //Set to FALSE
popup.Margin = Padding.Empty;
popup.Padding = Padding.Empty;
ToolStripControlHost host = new ToolStripControlHost(userControl1);
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
popup.Items.Add(host);
popup.Show(button1, new Point(100,100));
Actual Solution should be the one in Martin's final comment:
Use ContextMenu Instead of ContextMenuStrip
That one worked for me, and the ToolStripDropDown no longer closes by itself when right clicking one of its content controls, like it should. We still need it to AutoClose, disabling AutoClose on ToolStripDropDown will do bad things, it is supposed to close on losing focus. Example: open any other app window, and the ToolStripDropDown will continue to appear on top

Resources