Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
GeneralRe: another textbox question Pin
[Marc]15-Dec-05 6:19
[Marc]15-Dec-05 6:19 
GeneralRe: another textbox question Pin
melanieab15-Dec-05 7:50
melanieab15-Dec-05 7:50 
GeneralRe: another textbox question Pin
[Marc]15-Dec-05 8:19
[Marc]15-Dec-05 8:19 
GeneralRe: another textbox question Pin
melanieab15-Dec-05 7:46
melanieab15-Dec-05 7:46 
QuestionBrowser Activity Monitor Pin
TAREQ F ABUZUHRI14-Dec-05 5:33
TAREQ F ABUZUHRI14-Dec-05 5:33 
QuestionX and Y coordinates that follow mouse cursor? Pin
...---...14-Dec-05 5:23
...---...14-Dec-05 5:23 
AnswerRe: X and Y coordinates that follow mouse cursor? Pin
WillemM14-Dec-05 9:30
WillemM14-Dec-05 9:30 
QuestionSingle instance of a form Pin
PHDENG8114-Dec-05 4:28
PHDENG8114-Dec-05 4:28 
I have a project that had a Mainscreen that calls several forms via dll's. Visual inheritance if you will. There can only be one instance of each form running at a time. Therefore, I have the following class to pass each form through:

using System;
using System.Windows.Forms;
using System.Collections.Specialized;

using System.Runtime.InteropServices;


namespace FormManager

{
public class FormLoader

{
private static HybridDictionary m_InitializedForms = new HybridDictionary();

public static void LoadFormType(Type formType)
{

Form frm = (Form)Activator.CreateInstance(formType);

if (IsAlreadyLoaded(formType))
{
frm.BringToFront();//this does not work.
return;
}

FlagAsLoaded(formType);
frm.Closed += new EventHandler(FormClosed);
frm.Show();

}

private static void FlagAsLoaded(Type formType)
{
m_InitializedForms[formType.Name] = true;
}

private static void FlagAsNotLoaded(Type formType)
{
m_InitializedForms[formType.Name] = false;
}

private static bool IsAlreadyLoaded(Type formType)
{
return ((m_InitializedForms[formType.Name] != null) &&
(bool)m_InitializedForms[formType.Name] == true);
}

private static void FormClosed(object sender, EventArgs e)
{
Form closingForm = (Form)sender;
closingForm.Closed -= new EventHandler(FormClosed);
FlagAsNotLoaded(sender.GetType());
}

}

}

So, on the mainscreen I would simply call the Form2 from a button_click event like so:

FormLoader.LoadFormType(typeof(Form2));

This works great. However, when I click on the button again, it does not bringtofront or have focus. I have done something very similar to this and it worked fine. I tried using the WIN32 API to bring it to front as well. That would instantiate another form. Still, no luck. Any suggestions would be great. Thanks in advance.



-- modified at 10:29 Wednesday 14th December, 2005
AnswerRe: Single instance of a form Pin
S. Senthil Kumar14-Dec-05 5:38
S. Senthil Kumar14-Dec-05 5:38 
AnswerRe: Single instance of a form Pin
Curtis Schlak.14-Dec-05 5:42
Curtis Schlak.14-Dec-05 5:42 
GeneralRe: Single instance of a form Pin
PHDENG8114-Dec-05 6:51
PHDENG8114-Dec-05 6:51 
GeneralRe: Single instance of a form Pin
Curtis Schlak.14-Dec-05 7:20
Curtis Schlak.14-Dec-05 7:20 
GeneralRe: Single instance of a form Pin
PHDENG8114-Dec-05 7:01
PHDENG8114-Dec-05 7:01 
GeneralRe: Single instance of a form Pin
Curtis Schlak.14-Dec-05 7:18
Curtis Schlak.14-Dec-05 7:18 
GeneralRe: Single instance of a form Pin
Curtis Schlak.14-Dec-05 7:25
Curtis Schlak.14-Dec-05 7:25 
GeneralRe: Single instance of a form Pin
PHDENG8114-Dec-05 8:16
PHDENG8114-Dec-05 8:16 
GeneralRe: Single instance of a form Pin
Curtis Schlak.14-Dec-05 10:40
Curtis Schlak.14-Dec-05 10:40 
GeneralRe: Single instance of a form Pin
PHDENG8119-Dec-05 2:27
PHDENG8119-Dec-05 2:27 
QuestionWrapper for BITS Pin
oddstar14-Dec-05 4:24
oddstar14-Dec-05 4:24 
AnswerRe: Wrapper for BITS Pin
WillemM14-Dec-05 9:27
WillemM14-Dec-05 9:27 
Questionwhich textbox is entered? Pin
melanieab14-Dec-05 4:04
melanieab14-Dec-05 4:04 
AnswerRe: which textbox is entered? Pin
J4amieC14-Dec-05 4:21
J4amieC14-Dec-05 4:21 
GeneralRe: which textbox is entered? Pin
melanieab14-Dec-05 5:03
melanieab14-Dec-05 5:03 
AnswerRe: which textbox is entered? Pin
anandss14-Dec-05 11:11
anandss14-Dec-05 11:11 
QuestionProblem in gridview(asp.net (C#)) Pin
montu337714-Dec-05 3:56
montu337714-Dec-05 3:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.