Forms bloody Forms

Posted on 2010-01-07
Last Modified: 2013-12-17
Hi everyone,

I currently find myself having to build a windows application and unfortunetly lack the experience with forms.
So, what I have is a mdi container and in this container the user can open up and number of forms, but I want to be able to limit them to 10 forms, and be able to reuse these forms as they may be able to open x versions of the same form at a time.
I suppose I need some tpe of queue.
I have tried declaring the forms pointing to a dummy form I have ie.
blah.blankForm = f1, f2, f3, f4, f5, f6, f7, f8, f9, f10;
but then when I want to assign f1 to a different for it chucks an error
f1 = new dummyForm();

I have no idea how else to approach this. So any help would be fantastic.

Question by:Saber37886661
    LVL 9

    Expert Comment

    Please post your code along with the error message. It's much easier to help you if we can see the code
    LVL 3

    Author Comment

    magicdlf I have no code if I did then chances are I could figure it out myself. I only know the concept of what I want to do but have no idea how to implement it.

    Please read my problem again.
    LVL 43

    Expert Comment

    What I would do is intercept the OnNewDocument and OnOpenDocument calls.  Then count how many documents are currently opened, if it is at your limit (eg. 10) then take whatever action you want.

    (Junking what is in an open document could annoy the user - it really depends on what they are and how people work with them).
    LVL 3

    Author Comment

    Hi Andy,
    I can count the open forms fine, but I dont know how to declare them all as non specific forms.

    Ill try and explain again, I am not sure if this confusion is me not explaining this right.

    Say you have a mdi parent form. It has say 30 different options off the menu, all which open a new form.

    But I only want to be able to have 10 forms open at a time, and I want to be able to have 10 copies of 1 type of form open if I want.

    So say for example My menu's first item is User Controls. Clicking this would open a form called UserControls. Normally you would have somethign like:
    UserControls frmUserControls = new UserControls();
    frmUserControls.MdiParent = this;

    But for me to then allow 10 versions of the forms to open then I would need 10 seperate declarations of the form. That would mean 300 form declarations.

    So rather then do that, I want to be able to have 10 blank public forms declared that I can then dynamically assign the form to.

    so for instance
    frm1, frm2, frm3, frm4, frm5, frm6, frm7, frm8, frm9, frm10 would all be blank public forms

    then I could assign the new form to it when it was needed like
    frm1 = new UserControls();
    frmUserControls.MdiParent = this;

    Does that make it a bit less confusing?
    LVL 43

    Accepted Solution

    I think so.
    So in response to the OnNew/OnOpen you iterate the currently existing documents/views.  For sake of example say you have a type1 and a type2.  Now if there are 10 of type1 open and two of type2 then the user can open more type2 but no more type1.
    So all you need is a variable in the view that lets you know which type of view it is.

    Frm_type1 : Frm_base : Form
    Frm_type2 : Frm_base : Form

    Frm_base contains the variable to determine what type of document/view you have.
    LVL 3

    Author Comment

    Hi Andy,
    I have no idea if what you said was right but I got it working right.
    After seeing what you wrote the penny dropped and my problem was that I was declaring the forms down to the nth degree when I needn't.
    Just declaring:
    Form f1, f2, f3, f4, f5, f6, f7, f8, f9, f10;
    is enough because then I can assign to them at will like:
    switch (sender.ToString())
            case "User Login History":
                f1 = new WebRD_Client.admin.User.UserHistory();
                f1.MdiParent = this;
            case "User Tools":
                f1 = new WebRD_Client.admin.User.UserTools();
                f1.MdiParent = this;
    (I havent worried about the checking to see what form is empty yet)

    So thankyou for your help :)
    LVL 3

    Author Closing Comment

    Thanks alot for your help :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now