This is a migrated thread and some comments may be shown as answers.

Form Single Instance and Activate it

5 Answers 56 Views
Form
This is a migrated thread and some comments may be shown as answers.
Ganeshram
Top achievements
Rank 1
Ganeshram asked on 14 Feb 2008, 10:23 PM
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

5 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 18 Feb 2008, 02:00 PM
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
0
Ganeshram
Top achievements
Rank 1
answered on 04 Apr 2008, 01:41 AM
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
0
Ganeshram
Top achievements
Rank 1
answered on 04 Apr 2008, 06:56 AM
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? 




        




 
0
Ganeshram
Top achievements
Rank 1
answered on 04 Apr 2008, 09:47 AM

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;

}

0
Nikolay
Telerik team
answered on 08 Apr 2008, 11:08 AM
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
Tags
Form
Asked by
Ganeshram
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Ganeshram
Top achievements
Rank 1
Share this question
or