[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Forms bloody Forms

Posted on 2010-01-07
7
Medium Priority
?
225 Views
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.

Cheers
Matt
0
Comment
Question by:Saber37886661
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

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

Author Comment

by:Saber37886661
ID: 26208114
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.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26208155
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).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Saber37886661
ID: 26208255
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;
frmUserControls.Show()

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;
frmUserControls.Show()

Does that make it a bit less confusing?
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 26208302
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.
0
 
LVL 3

Author Comment

by:Saber37886661
ID: 26208427
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;
            f1.Show();
            break;
        case "User Tools":
            f1.Close();
            f1.Dispose();
            f1 = new WebRD_Client.admin.User.UserTools();
            f1.MdiParent = this;
            f1.Show();
           break;
}
(I havent worried about the checking to see what form is empty yet)

So thankyou for your help :)
0
 
LVL 3

Author Closing Comment

by:Saber37886661
ID: 31674437
Thanks alot for your help :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

831 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