I have some stuff in the OnShow event of a main form that fills a few listboxes with a procedure StuffLB. I need these listboxes refilled after any of my other forms have been shown with a call to ShowModal.
After such a modal form closes, the main form is just repainted there where the modal form was and its OnShow event does not fire.
The only way I can get the OnShow event to fire is by:
frmM.Hide;
frmB.ShowModal;
frmM.Show;
Is the only way I can get the listboxes filled to use the StuffLB call after every ShowModal call on sub forms? I have about 25 forms that are available.
I would had hoped that OnShow meant when it was shown again, either in part or in full.
I'd appreciate any help or suggestions.
OnShow event fires when form becomes visible. What you may use is OnActivate event. However, since it is your code that calls ShowModal of another form, just put required code in a separate method and call here and in FormShow.
ExtJS 4.1.
Is there something like Ext.button.click(); method on Ext.button class?
Is it possible to programmically "click" a button with one method?
Or if you have an MVC structure you can fire the click event of the button, and if you're listening to the event in your controller and have an associated function it will get called.
button.fireEvent('click', button);
The last answer on this forum might give you more insight on how you can do that
here they are-
1)Create the event code in a function and call the function from both sides: btn.on("clic", ...) and from the code you want to simulate the click.
2)Use: btnView.btnEl.dom.click();
from -
http://www.sencha.com/forum/showthread.php?37772-Solved-Programmatically-click-an-Ext.Button
ExtJS 4.2.1
Ext.get('component-id-of-extjs-button').el.dom.click();
Ext.get('toggle-button2').el.dom.click();
works for me.
In case of buttons using handler, you can directly call the function of button.
Considering button is an Ext JS component, you can use:
button.handler(button);
or if you want to reach a function of event 'click':
button.listeners.click(button);
That would also work to call different button events.
Since I needed it for many buttons, it was easier to implement an override on the button class, which adds a click function:
Ext.define('Ext.override.Button',{
override:'Ext.button.Button',
click:function() {
this.getEl().dom.click();
}
})
After this override has been added to the code base, the following works like a charm:
Ext.getCmp("MyButton").click()
Unlike fireEvent or fireHandler, this will work with all kinds of buttons - no matter whether they have a click event or a handler, or whether they are toggle buttons where the clicked button has to be marked as pressed also.
If you need to execute the "handler" of the button, just run this (tested with ExtJS 4.2)
button.fireHandler()
If you want to do this in your test scripts, take a look at my Ext.ux.Test library. If you need it for something other, I would suggest reconsidering your approach.
None of the other answers worked for me, but i found something simplier i think :
var button=Ext.get('the_id_div');
button.dom.click();
document.getElementById("someButtonId").click();
Is there a way to do something like this?
Background:
I have a button click. When the button is clicked I try to show a "loading" message, run a bunch of code that does some UI work and then dismiss the "loading" message. It takes anywhere from a few seconds to 20 seconds usually. At the moment the loading message doesn't show at all and the UI freezes until the code in my button click is done.
I've read about Background Worker and dispatcher, but haven't been able to get it to work. I'm not sure if it's because the code in the button click calls all sorts of other code (including 3rd party stuff), but I haven't been able to get it to run correctly. It all still works, but it still freezes the UI and the loading message doesn't appear.
So, I am wondering if there is another way around this. Is it possible to set it up so that on the button click I only show the loading message and then a second or so later fire another event that executes my long running process? That way the UI will still freeze for some seconds, but at least it will show a "loading" message.
You should be able to do this with a Dispatcher.BeginInvoke call.
private void ButtonClick(object sender, EventArgs e)
{
ShowMyLoadingMessage(); // your code, not sure what it is
Dispatcher.BeginInvoke(() =>
{
CallMyLongRunningCode(); // again, not sure what this is
HideMyLoadingMessage();
}
}
I don't believe this is the best solution since it is running on the UI thread, but it should do what you are asking.
What is the long running code doing that takes 20 seconds?
I have one "CleanUp" button on my WPF UI.By clicking on this button, I"ll call some C++ wrapper function to do some calculation.The calculation will take some time.
What I want exactly:
1. During calculation, I want to show some message like "Clean-Up is going on" besides one node of TreeView (TreeView is present on same UI.
Any help would be appreciated........
You can try by using a BackgroundWorker.
Just set a new background worker and set it's dowork event to your "wrapper function to do some calculation" ;-)
After that you can trigger the reportprogress event to set a new state or message while it's executing.
In my application I call App.Current.MainWindow.Show()/App.Current.MainWindow.Hide() to show/hide my application but I don't know how to catch the event when the form is hidden/showed. Please help if you know how to!
One of your tags is WPF and the other is WinForms... I'm better with WinForms, so I'll answer for that tag.
The Form.Shown event documentation is here with sample code...
There is no corresponding Form.Hidden event. The best you can do is choose from Form.Closing or Form.Closed or one of the other events.
Added from my comment above
Question - if you're CALLING the Hide and Show in your code, why do you need to capture the events? You already KNOW when it's happening. If you want to run some code inside the form after hiding and closing it, expose the code as a public function, and call the function after showing and hiding the form...