Form Single Instance and Activate it

6 posts, 0 answers
  1. Ganeshram
    Ganeshram avatar
    14 posts
    Member since:
    Feb 2008

    Posted 14 Feb 2008 Link to this post

    Hi,
    I'm using dock panel and shaped form and its a MDI application.My requirement is I should always have only one instance of the form .Create if it is not available or activate it.I used Singleton pattern to acheive this.

    I have problems activating it or showing it next time.I couldn't find any sample .
    Please advice with the exact sample

    thanks in advance
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 18 Feb 2008 Link to this post

    Hi Ganeshram,

    Thank you for writing us.

    I have attached a sample program that reproduces the desired behavior. When you click the button Show/Hide, you get the only instance of the mdi child form. Then you show or hide this form depending on its current state.

    If you need additional assistance, do not hesitate to contact us.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ganeshram
    Ganeshram avatar
    14 posts
    Member since:
    Feb 2008

    Posted 03 Apr 2008 Link to this post

    Hi Support,
    Thanks this works.But surpringly I found that my project doesn't use MDIParent - MDI Child concept rather uses Docking Manager and Panel similar to your samples
    When I try to implement the same ?It works for the first time,when click second time,it shows blank form.

    Not sure whether I should call .refresh or initializecomponent.Please assist
  5. Ganeshram
    Ganeshram avatar
    14 posts
    Member since:
    Feb 2008

    Posted 04 Apr 2008 Link to this post

    One correction.Yes It uses the MDI Parent -Child relation pattern,using Docking Panel.I can see one thing very weird.If I try to run in debug mode ,I can see the screen comes up second time.Never in release mode.

    if (frmJobSummary is nothing )
        frmJobSummary=FrmJobSummary.GetInstance();

    if not frmJobSummary is nothing and not frmJobSummary.isDisposed then
         if (frmJobSummary.isvisible=true)
                frmJobSummary.activate()
                frmJobSummary.refresh()
        else
                frmJobSummary.show()
                frmJobSummary.refresh()
        end if
    else
        frmJobSummary =FrmJobSummary.GetInstance()
        frmJobSummary.Show()

    I doubt some thing is missing here? 




            




     
  6. Ganeshram
    Ganeshram avatar
    14 posts
    Member since:
    Feb 2008

    Posted 04 Apr 2008 Link to this post

    Some how I'm able to get some sample from http://www.telerik.com/community/forums/thread/b311D-bbgeae.aspx

    dockingManager1.SetDocument((DocumentPane)form.Parent) is throwing error saying cannot typecast from mdiclient to documentpane.Please assist.

    cRewardsForms
    objcRewardsForms = new cRewardsForms();//Collectuion Class

    BaseForm objBaseForm;

    #region

    "Manage Form Display"

    private void Display(string formName, string relatedForm)

    {

    if (objcRewardsForms[formName] != null)

    {

    objBaseForm = objcRewardsForms[formName];

    if (objBaseForm == null || objBaseForm.IsDisposed)

    {

    objBaseForm = GetInstance(formName);

    if (objBaseForm != null)

    objcRewardsForms[formName] = objBaseForm;

    }

    }

    else

    {

    objBaseForm = GetInstance(formName);

    if (objBaseForm != null)

    objcRewardsForms.Add(formName, objBaseForm);

    }

    if (objBaseForm != null)

    {

    objBaseForm.MdiParent =

    this;

    if (objBaseForm.Visible)

    {

    objBaseForm.Activate();

    for (int i = 0; i < dockingManager.MdiChildren.Length; i++)

    {

    Form f;

    f = dockingManager.MdiChildren[i];

    if (f.Name == formName)

    {

    dockingManager.SetDocument((

    DocumentPane)objBaseForm.Parent);

    }

    }

    }

    else

    {

    DocumentPane documentPane = new DocumentPane();

    documentPane.Text = objBaseForm.Name;

    objBaseForm.Parent = documentPane;

    objBaseForm.Show();

    }

    }

    else

    MessageBox.Show("Error");

    HideOtherForms(formName, relatedForm);

    }

    private BaseForm GetInstance(string formName)

    {

    if (formName == "SingleForm")

    return SingleForm.Instance;

    else if (formName == "SingleForm2")

    return SingleForm2.Instance;

    else if (formName == "Details")

    return Details.Instance;

    else

    return null;

    }

  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 08 Apr 2008 Link to this post

    Hi Ganeshram,

    Please find the answer to your question in the support ticket you have opened.

    Best wishes,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready