判斷 form 是否開啟

1 篇文章 / 0 new
author
判斷 form 是否開啟
► for class
//use findForm(typeof(ContainerInEditForm)
public static Boolean findForm(Type FormType)
{
    foreach (Form form in Application.OpenForms)
    {
        if (form.GetType() == FormType)
        {
            form.WindowState = FormWindowState.Normal;
            form.Show();
            form.BringToFront();
            form.Activate();
            return false;
        }
    }
    return true;
}

► for name
//use findForm("ContainerInEditForm") <= Form.name
public static Boolean findForm(string formName)
{
    Form form = Application.OpenForms[formName];
    if (form != null)
    {
        form.WindowState = FormWindowState.Normal;
        form.Show();
        form.BringToFront();
        form.Activate();
        return false;
    }
    else
        return true;
}
► 建立實例
public static T CreateInstance<T>() where T : new()
{
    // Do some business logic
    return new T();
}
Free Web Hosting