need help or advice... [modified]
-
private void WhatFormToShow(Form f) { f.MdiParent = this; f.Dock = DockStyle.Fill; f.Show(); // this.pnlCompositeCon.Controls.Clear(); this.pnlCompositeCon.Controls.Add(f); this.txtCurrentLoadedForm.Text = f.Name.ToUpper(); } WhatFormToShow(FrmAdd);
when i call the function i got this error, that said "its a 'type' but us used like a 'variable'...what is the proper way of doing this? please help -- modified at 3:18 Saturday 14th October, 2006
-
private void WhatFormToShow(Form f) { f.MdiParent = this; f.Dock = DockStyle.Fill; f.Show(); // this.pnlCompositeCon.Controls.Clear(); this.pnlCompositeCon.Controls.Add(f); this.txtCurrentLoadedForm.Text = f.Name.ToUpper(); } WhatFormToShow(FrmAdd);
when i call the function i got this error, that said "its a 'type' but us used like a 'variable'...what is the proper way of doing this? please help -- modified at 3:18 Saturday 14th October, 2006
What is the exact (!) error message you get? The compiler won't tell you "its a 'type'". What is 'its'? Could it be that
FrmAdd
is the name of your form class and not the name of a form instance?Regards, mav -- Black holes are the places where God divided by 0...
-
private void WhatFormToShow(Form f) { f.MdiParent = this; f.Dock = DockStyle.Fill; f.Show(); // this.pnlCompositeCon.Controls.Clear(); this.pnlCompositeCon.Controls.Add(f); this.txtCurrentLoadedForm.Text = f.Name.ToUpper(); } WhatFormToShow(FrmAdd);
when i call the function i got this error, that said "its a 'type' but us used like a 'variable'...what is the proper way of doing this? please help -- modified at 3:18 Saturday 14th October, 2006
All I can do is guesses. I guess that you get the error at this line:
WhatFormToShow(FrmAdd);
and I guess that
FrmAdd
is a class name. Is this the case? If so you have to pass an object no a class to the method.Regards:rose:
-
All I can do is guesses. I guess that you get the error at this line:
WhatFormToShow(FrmAdd);
and I guess that
FrmAdd
is a class name. Is this the case? If so you have to pass an object no a class to the method.Regards:rose:
thanks for reply :) Yup i want to pass the form class name so i can instantiate the form by using the function. Im tired of typing...
FrmNew myF = new FrmNew(); // // insert additional form setting. // ex: .windowstate/.location // myF.Show();
or if there are more form setting to setup. i want to pass the form name so the function can create it and instantiate it automatically. Im new to c# any links to enlighten me more on this subject please dont hesitate to point me to the right direction :) Thanks :)
-
thanks for reply :) Yup i want to pass the form class name so i can instantiate the form by using the function. Im tired of typing...
FrmNew myF = new FrmNew(); // // insert additional form setting. // ex: .windowstate/.location // myF.Show();
or if there are more form setting to setup. i want to pass the form name so the function can create it and instantiate it automatically. Im new to c# any links to enlighten me more on this subject please dont hesitate to point me to the right direction :) Thanks :)
While you can achieve something like this using reflection, I strongly doubt that you should do it. Giving "I'm tired of typing..." as the reason simply isn't enough. What are the advantages you get for the flexibility you lose?
Regards, mav -- Black holes are the places where God divided by 0...
-
thanks for reply :) Yup i want to pass the form class name so i can instantiate the form by using the function. Im tired of typing...
FrmNew myF = new FrmNew(); // // insert additional form setting. // ex: .windowstate/.location // myF.Show();
or if there are more form setting to setup. i want to pass the form name so the function can create it and instantiate it automatically. Im new to c# any links to enlighten me more on this subject please dont hesitate to point me to the right direction :) Thanks :)
Well, you want to make some sort of a Froms factory!! This is possible, but as Mav said... Why?? Each form has its own special properties to be initialized. Why don't you initialize them at design time once?? Anyway, I'm not in the position to judge or modify your coding style. All I wanted was to guide you to what I think is better than what you want. Trust me, this isn't the reason to make such a factory method. Anyway, you can do it -like Mav said again- using Reflection namespace. 1- Declare your method as
MyMethod(Type TheForm)
2- Call it as
MyMethod(typeof(FormClassName));
3- In the Form you can call
Assembly.CreateInstance()
to create your form. Then using this object you can initialize it. Yet, again... Does it really worth all this??Regards:rose:
-
Well, you want to make some sort of a Froms factory!! This is possible, but as Mav said... Why?? Each form has its own special properties to be initialized. Why don't you initialize them at design time once?? Anyway, I'm not in the position to judge or modify your coding style. All I wanted was to guide you to what I think is better than what you want. Trust me, this isn't the reason to make such a factory method. Anyway, you can do it -like Mav said again- using Reflection namespace. 1- Declare your method as
MyMethod(Type TheForm)
2- Call it as
MyMethod(typeof(FormClassName));
3- In the Form you can call
Assembly.CreateInstance()
to create your form. Then using this object you can initialize it. Yet, again... Does it really worth all this??Regards:rose:
I see. Thanks mav and nader :) I really wanted to implement this as part of my UI. I have created an mdi application that mimic the MS MONEY 2006 tab bar tab ---> HOME BILLING INVENTORY So if i click on the HOME TAB, it will only load a single form. this is all done in my FrmMain. this is why i have this sub.
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
FrmHome F1 = new FrmHome()
F1.MdiParent = this;
F1.Dock = DockStyle.Fill;
F1.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F1);
this.txtCurrentLoadedForm.Text = F1.Name.ToUpper();
break;
case "BILLING":
FrmHome F2 = new FrmHome()
F2.MdiParent = this;
F2.Dock = DockStyle.Fill;
F2.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F2);
this.txtCurrentLoadedForm.Text = F2.Name.ToUpper();break; case "INVENTORY": FrmHome F3 = new FrmHome() F3.MdiParent = this; F3.Dock = DockStyle.Fill; F3.Show(); // this.pnlCompositeCon.Controls.Clear(); this.pnlCompositeCon.Controls.Add(F3); this.txtCurrentLoadedForm.Text = F3.Name.ToUpper(); break; } }
So i could have used the function
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
WhatFormToLoad(FrmHome);
break;
case "BILLING":
WhatFormToLoad(FrmBilling);
break;
case "INVENTORY":
WhatFormToLoad(FrmInventory);
break;
}
}This is much easier than typing all those redundant settings :) Thats why i have decide to create a generic routine or a form factory to catter the loading of forms by just passing the form name. If im not on the rig
-
I see. Thanks mav and nader :) I really wanted to implement this as part of my UI. I have created an mdi application that mimic the MS MONEY 2006 tab bar tab ---> HOME BILLING INVENTORY So if i click on the HOME TAB, it will only load a single form. this is all done in my FrmMain. this is why i have this sub.
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
FrmHome F1 = new FrmHome()
F1.MdiParent = this;
F1.Dock = DockStyle.Fill;
F1.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F1);
this.txtCurrentLoadedForm.Text = F1.Name.ToUpper();
break;
case "BILLING":
FrmHome F2 = new FrmHome()
F2.MdiParent = this;
F2.Dock = DockStyle.Fill;
F2.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F2);
this.txtCurrentLoadedForm.Text = F2.Name.ToUpper();break; case "INVENTORY": FrmHome F3 = new FrmHome() F3.MdiParent = this; F3.Dock = DockStyle.Fill; F3.Show(); // this.pnlCompositeCon.Controls.Clear(); this.pnlCompositeCon.Controls.Add(F3); this.txtCurrentLoadedForm.Text = F3.Name.ToUpper(); break; } }
So i could have used the function
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
WhatFormToLoad(FrmHome);
break;
case "BILLING":
WhatFormToLoad(FrmBilling);
break;
case "INVENTORY":
WhatFormToLoad(FrmInventory);
break;
}
}This is much easier than typing all those redundant settings :) Thats why i have decide to create a generic routine or a form factory to catter the loading of forms by just passing the form name. If im not on the rig
Well, you can use generics;P Or much simpler, this:
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
{
FrmHome frm = new FrmHome();
WhatFormToLoad(Frm);
break;
}
case "BILLING":
{
FrmBilling frm = new FrmBilling();
WhatFormToLoad(Frm);
break;
}
case "INVENTORY":
{
FrmInventory frm = new FrmInventory();
WhatFormToLoad(Frm);
break;
}
}
}private void WhatFormToLoad(Form MyForm)
{
MyForm.MdiParent = this;
MyForm.Dock = DockStyle.Fill;
MyForm.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(MyForm);
this.txtCurrentLoadedForm.Text = MyForm.Name.ToUpper();
}Regards:rose:
-
Well, you can use generics;P Or much simpler, this:
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
{
FrmHome frm = new FrmHome();
WhatFormToLoad(Frm);
break;
}
case "BILLING":
{
FrmBilling frm = new FrmBilling();
WhatFormToLoad(Frm);
break;
}
case "INVENTORY":
{
FrmInventory frm = new FrmInventory();
WhatFormToLoad(Frm);
break;
}
}
}private void WhatFormToLoad(Form MyForm)
{
MyForm.MdiParent = this;
MyForm.Dock = DockStyle.Fill;
MyForm.Show();
//
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(MyForm);
this.txtCurrentLoadedForm.Text = MyForm.Name.ToUpper();
}Regards:rose:
Thanks for the Prompt reply, nader :) I was about to go on this direction. As i was playing with the Refactoring menu :cool: anyway thanks for the input :) its highly appreciated :)