views:

124

answers:

0

I have a loading dialog that I show with a static method. The loading dialog class is as follows:

using System.Threading;
using System.Drawing;
using System.Windows.Forms;

namespace Pf.PfGui2010.Gui.Base
{
public class PFLoadingDialog : DevExpress.Utils.WaitDialogForm
{

    private static PFLoadingDialog form;
    private static Thread _thread;
    private static string _caption;
    private static string _title;
    private static Form _frmParentForm;
    private static Size _size = new Size(200, 50);

    private PFLoadingDialog(string caption, string title)
        : base(caption, title, _size, _frmParentForm)
    {

    }

    private static void CreateInstance()
    {
        form = new PFLoadingDialog(_caption, _title);
        Application.Run(form);
    }

    public static void Show(string caption, string title, Form rParentForm)
    {
        _caption = caption;
        _title = title;
        _frmParentForm = rParentForm;

        if (form == null)
        {
            _thread = new Thread(CreateInstance);
            _thread.IsBackground = true;
            _thread.Start();
        }
    }

    public new static void SetCaption(string caption)
    {
        if (form != null)
        {
            _caption = caption;
            form.SetFormCaption();
        }
        else
        {
            Show(caption, "", _frmParentForm);
        }
    }

    public new static void Close()
    {
        if (form != null)
        {
            form.CloseForm();
            form = null;

        }
    }





    private void CloseForm()
    {
        if (this.InvokeRequired)
        {
            Invoke(new MethodInvoker(CloseForm));
            return;
        }
        Application.ExitThread();
    }

    private void SetFormCaption()
    {
        if (this.InvokeRequired)
        {
            Invoke(new MethodInvoker(SetFormCaption));
            return;
        }

        base.SetCaption(_caption);
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        //
        //LoadingDialog
        //
        this.ClientSize = new System.Drawing.Size(219, 68);
        this.Location = new System.Drawing.Point(0, 0);
        this.Name = "LoadingDialog";
        this.ResumeLayout(false);
    }

}

}

In my main form, at some instant, I call PFLoadingDialog.Show(). Then, on an event that follows this, I call the following:

private void OnControlGroupResponseProcessed(object sender, PFResponseProcessedEventArgs e)
    {
        if (this.InvokeRequired)
        {
            EnableFormCallback cb = new EnableFormCallback(enableForm);
            this.Invoke(cb);
        }
        else
        {
            enableForm();
        }
    }

delegate void EnableFormCallback();
    private void enableForm()
    {
        this.Activate();
        PFLoadingDialog.Close();
        if (!this.Enabled)
        {
            this.Enabled = true;
        }
    }

Now, everything up until here works normally. The dialog is shown, and then closed. However, something weird happens when it is closed. My main form has a scrollable control on the left side, and when the loading dialog is closed, the control is automatically scrolled down!

What could be the reason of this? As far as I see, nothing should be happening that affects the scroll position...Any ideas??