views:

26

answers:

1

Hello

I have a simple two forms, one that contains a grid and a button. When I click the button, my application starts doing a long operation. While it is working, I show another form that contains a progress bar I open it like this:

_busyWindow.ShowDialog();

And defined

public partial class BusyWindow :  DevExpress.XtraEditors.XtraForm
{
    public BusyWindow()
    {
        InitializeComponent();
    }

    private void BusyWindow_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.Hide();
        e.Cancel = true; // this cancels the close event.
    }
}

When the operation is finished, I hide the form like this

if (ended)
    _busyWindow.Hide();

It works fine. The problem is that when I close the second form (same closing code), it also closes fine but my main GUI loses the focus. For example, if I have the Firefox opened behind the application, then the Firefox gets the focus.

This only happens when I close the second form when the busyWindow has been opened, and no when it hasn't (ie, if I open the form, I close it without clicking on the button, then the main GUI doesn't lose the focus).

Do you know what is happening or where could I try to search?

+1  A: 
Vaibhav
thanks! it worked!
pedroruiz
good... just for info. the 1st solution or the 2nd one ? Guess, it was the first one!
Vaibhav
I just found it doesn't work always :(The first didn't work, the second seemed to work, but sometimes it doesnt
pedroruiz
If you set the focus to your main window before hiding the busy window, i think your sometimes issue will vanish. Try it out and revert. Have faced these issues a plenty while doing WinForms development. Just focus the mainWindow before hiding the busyWindow.
Vaibhav