CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    7

    C# Form inheritance with new controls

    HI guys

    I have a main form and created a class that inherits from the main form :

    namespace ClientServices
    {
    class ControllerClass : ClientServices
    {
    }
    }

    What happens now is that the ControllerClass looks like the ClientService!

    The Problem that I have is that now that I add New controls to the ControllerClass (Via the toolbox) they show but as soon as I compile the application they disappear! Even when you stop the compilation they are gone but the code is still there?

    Can anyone please advice?

    Thanks

  2. #2
    Join Date
    Jun 2011
    Posts
    7

    Re: C# Form inheritance with new controls

    for example :

    namespace ClientServices
    {
    class ControllerClass : ClientServices
    {
    public void AddButton()
    {

    Button btn = new Button();
    btn.Text = "New Button";
    btn.Location = new Point(100, 100);

    panel1.Controls.Add(btn);
    }

    }
    }


    and then my :

    private void TrVHIMenue_AfterSelect(object sender, TreeViewEventArgs e)
    {
    ControllerClass c = new ControllerClass();
    c.AddButton();
    }

    CAN ANYONE HELP?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: C# Form inheritance with new controls

    Visual inheritance was allways trouble in VisualStudio, so I would prefere composition of user controls over inheritance. But if you really need it, check the z-order of the controls in the designer, and if you want to put the control into a panel from the ancestor, be sure that the modifier of the panel is protected.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured