Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Release Photo Pin
sanforjackass26-Aug-09 2:16
sanforjackass26-Aug-09 2:16 
QuestionHelp needed with simple Web Spider Code Pin
manormi125-Aug-09 16:02
manormi125-Aug-09 16:02 
AnswerRe: Help needed with simple Web Spider Code Pin
N a v a n e e t h25-Aug-09 16:41
N a v a n e e t h25-Aug-09 16:41 
QuestionimageList images appear to be getting "corrupted" Pin
shultas25-Aug-09 14:54
shultas25-Aug-09 14:54 
AnswerRe: imageList images appear to be getting "corrupted" Pin
Henry Minute25-Aug-09 22:05
Henry Minute25-Aug-09 22:05 
QuestionRefactoring question Pin
Illegal Operation25-Aug-09 14:42
Illegal Operation25-Aug-09 14:42 
AnswerRe: Refactoring question Pin
Not Active25-Aug-09 15:03
mentorNot Active25-Aug-09 15:03 
AnswerRe: Refactoring question Pin
N a v a n e e t h25-Aug-09 16:26
N a v a n e e t h25-Aug-09 16:26 
Illegal Operation wrote:
My question is this, How can I make this code generic so that all my forms can inherit this functionality?


You need an easy method to instantiate forms and keep only one instance at a time, right? I'd try something like,
C#
public static class FormsRepository
{
    static Dictionary<Type, Form> cache = new Dictionary<Type, Form>();

    public static T GetFormInstance<T>() where T : Form, new()
    {
        Type type = typeof(T);
        T form = null;
        if (cache.ContainsKey(type))
        {
            if (cache[type] == null || cache[type].IsDisposed)
                cache[type] = new T();
            form = (T)cache[type];
        }
        else
        {
            form = new T();
            cache.Add(type, form);
        }
        return form;
    }
}
This code uses a Dictionary to keep the forms that are used. When you need an instance of Form2, you can write like.
C#
Form2 frm = FormsRepository.GetFormInstance<Form2>();
frm.Show();
Illegal Operation wrote:
makes sure that there will always only be one instance of a form open in my MDI app.


If there will be only one instance of forms, why call it MDI?

Smile | :)


QuestionConvert Process to the orginal C# COM class Pin
Gindi Bar Yahav25-Aug-09 13:07
Gindi Bar Yahav25-Aug-09 13:07 
Question[Message Deleted] Pin
WhiteWolf1925-Aug-09 11:49
WhiteWolf1925-Aug-09 11:49 
AnswerRe: C# code help Pin
Not Active25-Aug-09 12:20
mentorNot Active25-Aug-09 12:20 
AnswerRe: C# code help Pin
_Maxxx_25-Aug-09 19:38
professional_Maxxx_25-Aug-09 19:38 
QuestionEnumerator Pin
CodingYoshi25-Aug-09 11:06
CodingYoshi25-Aug-09 11:06 
AnswerRe: Enumerator Pin
Adam R Harris25-Aug-09 11:51
Adam R Harris25-Aug-09 11:51 
GeneralRe: Enumerator Pin
CodingYoshi25-Aug-09 17:20
CodingYoshi25-Aug-09 17:20 
AnswerRe: Enumerator Pin
DaveyM6925-Aug-09 11:51
professionalDaveyM6925-Aug-09 11:51 
AnswerRe: Enumerator Pin
Alan N25-Aug-09 13:45
Alan N25-Aug-09 13:45 
AnswerRe: Enumerator Pin
N a v a n e e t h25-Aug-09 16:36
N a v a n e e t h25-Aug-09 16:36 
GeneralRe: Enumerator Pin
CodingYoshi25-Aug-09 17:22
CodingYoshi25-Aug-09 17:22 
Questionbackgroundworker problem Pin
Planker25-Aug-09 10:26
Planker25-Aug-09 10:26 
AnswerRe: backgroundworker problem Pin
DaveyM6925-Aug-09 11:44
professionalDaveyM6925-Aug-09 11:44 
AnswerRe: backgroundworker problem Pin
N a v a n e e t h25-Aug-09 16:52
N a v a n e e t h25-Aug-09 16:52 
AnswerRe: backgroundworker problem Pin
Abdul Rahman Hamidy25-Aug-09 19:51
Abdul Rahman Hamidy25-Aug-09 19:51 
QuestionChanging Crystal Reports Details Section Height programmatically Pin
mj_developer25-Aug-09 9:29
mj_developer25-Aug-09 9:29 
QuestionSimple syntax error? Pin
Sonhospa25-Aug-09 9:26
Sonhospa25-Aug-09 9:26 

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.