Please accept my apologies.  This code is more accurate and will complile:
This code will work without having a BaseForm.  Instead use the Form class.

       private Dictionary<string, BaseForm> _forms = new Dictionary<string,
BaseForm>();

       /// <summary>
       /// Creates an instance of the specified form if it's not already
present in the list.
       /// </summary>
       /// <typeparam name="FormType"></typeparam>
       private BaseForm CreateForm<FormType>() where FormType : BaseForm {
           BaseForm form = null;
           string key = typeof(FormType).Name;
           if (!_forms.ContainsKey(key)) {
               form = new FormType();
               _forms.Add(key, form);
           } else {
               form = _forms[key];
           }
           //Additional code goes here...

           //Return the form.
           return form;
       }

To call the code to create your form use it like this (assuming each form
inherits from BaseForm)

Form1 form1 = CreateForm<Form1>();
...

Form1 form2 = CreateForm<Form1>();






On 2/13/07, Mike Andrews <[EMAIL PROTECTED]> wrote:

" A good
example of that is where I have 3 or 4 panels on a single form and I want
one keypress event to process every keypress on the form itself... as
opposed to having individual keypress events for each panel.
"

Any WinForm has a KeyPreview property that will cause all key events on
child controls to occur on the Form first before occuring on the control.

"What I want is something that loads the child
form within the parent form... and I don't want to have to control it.  I
figured that using an MDI form but only allowing the child forms to open
once copy of the form, would sort of give me the results I am looking for.
"
There are several ways to go about this for an MDI application.
In general if you need only one type of form open at once, you need to
have a dictionary keyed from the "type" of form you're using to generate and
the value being the form instance itself.

Here's is one example you might find useful.  You didn't specify a
language so I'll use C# here:


        private Dictionary<string, BaseForm> _forms = new
Dictionary<string, BaseForm>();

        /// <summary>
        /// Creates an instance of the specified form if it's not already
present in the list.
        /// </summary>
        /// <typeparam name="FormType"></typeparam>
        private BaseForm CreateForm<FormType>() where FormType: BaseForm {
            BaseForm form = null;
            if (!_forms.ContainsKey(typeof(FormType).Name)) {
                form = new FormType();
            }
            else {
                form = _forms[typeof(FormType)];
            }
            //Additional code goes here...

            //Return the form.
            return form;
        }

You can use this method to create a new form, or return you one that
already exists without having to know if it does or not.

 On 2/12/07, Jon Rothlander <[EMAIL PROTECTED]> wrote:
>
> I'm having some problems using the KeyPress event in various
> winForms.  I
> want to have a common keypress event set of code that will process of
> the
> F-Key presses.  I have the code worked up but I am finding that on
> different
> forms the event doesn't fire.  For example, when I added a tabbed
> control to
> the page, the form's keypress event stopped firing.  However, the tabbed
>
> control's keypress event is working.  So I just moved the code from the
> form's keypress event to the tabbed controls keypress event.  The
> problem
> here is that I only want one type of keypress event for ALL of my forms
> and
> sometimes I cannot find a keypress event that actually works.  A good
> example of that is where I have 3 or 4 panels on a single form and I
> want
> one keypress event to process every keypress on the form itself... as
> opposed to having individual keypress events for each panel.
>
> Any ideas how I could build a keypress event that would work on all
> forms
> regardless of what's on them?  Just one keypress for everything on the
> form.
> You figure that the form_keypress event would be what I am looking for.
> However, it doesn't always work.  Am I missing something?
>
> Also, I am trying to use an MDI parent/child form to create an IDE like
> UI
> for this application.  The problem here is that MDI isn't exactly what I
> need because you can only create ONE instance of each form.  So I do not
> want to create the traditional multi-document interface like used in
> something like Word or Excel.  What I want is something that loads the
> child
> form within the parent form... and I don't want to have to control
> it.  I
> figured that using an MDI form but only allowing the child forms to open
>
> once copy of the form, would sort of give me the results I am looking
> for.
>
> What I would like to know is if there is another way to handle
> this?  What I
> would like is something like how the .Net IDE works.  You have the
> parent
> form with child forms, but you can only open one instance of each child
> form
> at a time... as opposed to multi like you could in Word or Excel.
>
> How would you recommend this sort of IDE be built?  Should I be using
> the
> MDI parent/child forms?  Is there an easier way to build IDEs like this?
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>



===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to