Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. need help or advice... [modified]

need help or advice... [modified]

Scheduled Pinned Locked Moved C#
helpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheCardinal
    wrote on last edited by
    #1
        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

    M N 2 Replies Last reply
    0
    • T TheCardinal
          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

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0
      • T TheCardinal
            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

        N Offline
        N Offline
        Nader Elshehabi
        wrote on last edited by
        #3

        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:

        T 1 Reply Last reply
        0
        • N Nader Elshehabi

          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:

          T Offline
          T Offline
          TheCardinal
          wrote on last edited by
          #4

          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 :)

          M N 2 Replies Last reply
          0
          • T TheCardinal

            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 :)

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • T TheCardinal

              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 :)

              N Offline
              N Offline
              Nader Elshehabi
              wrote on last edited by
              #6

              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:

              T 1 Reply Last reply
              0
              • N Nader Elshehabi

                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:

                T Offline
                T Offline
                TheCardinal
                wrote on last edited by
                #7

                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

                N 1 Reply Last reply
                0
                • T TheCardinal

                  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

                  N Offline
                  N Offline
                  Nader Elshehabi
                  wrote on last edited by
                  #8

                  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:

                  T 1 Reply Last reply
                  0
                  • N Nader Elshehabi

                    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:

                    T Offline
                    T Offline
                    TheCardinal
                    wrote on last edited by
                    #9

                    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 :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups