Dynamic views

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jesper DK

    #1

    Dynamic views

    Hi,

    I'm writing a windows explorer like application. The GUI
    is divided by a vertical splitter. To the left I have a
    tree control. To the right of the splitter I would like
    to display one of several different user controls
    according to what is selected in the tree control. Now, I
    can do this by placing all of my different user controls
    on the form and then use .Show() and .Hide() on the
    controls. However, I do not fancy this technique, Isn't
    there a more elegant way of doing this.

    Another thing, If I instantiate these user controls
    dynamically and place them on the form, should they be
    placed on a panel?. Where should I store the reference to
    the user control.

    Thank you in advance.
    Best regards Jesper.
  • Noah Coad [MVP .NET/C#]

    #2
    Re: Dynamic views

    Hey Jesper,

    I do this exact same thing in several of my programs. There is a list of
    'commands', each has its own GUI interface so there is a spot where the
    correct control plugs in. Here are some things to consider:

    1. It would be a good idea, but not required, to make one UserControl
    control that is a basic version of the plug-in control. Then the specific
    plug-ins can all be extended from your 'template' instead of UserControl.
    This gives you more control over how they look and interact.

    2. Yes, put a panel where you want the controls to go, it makes things a
    little easier. Let's call it 'pnlHost'. All you really need to do is look
    at the Windows Designer Generate Code to see how controls are added via
    code. I'll give you what you need here.

    private void ShowControl(Use rControl c)
    {
    pnlHost.Control s.Clear(); // Remove any current controls in the panel
    pnlHost.Control s.Add(c); // Put the special control in the host panel
    c.Dock = DockStyle.Fill; // Make the control fill the host panel
    }

    Then say you have a custom control called "PageSettin gs", you want to show
    it in the host panel, just call: ShowControl(new PageSettings()) ;

    That's practically all there is to it!

    Good luck!

    -Noah Coad
    Microsoft MVP & MCP [.NET/C#]



    "Jesper DK" <jeodni@hotmail .com> wrote in message
    news:033a01c357 a6$9d3a57e0$a50 1280a@phx.gbl.. .[color=blue]
    > Hi,
    >
    > I'm writing a windows explorer like application. The GUI
    > is divided by a vertical splitter. To the left I have a
    > tree control. To the right of the splitter I would like
    > to display one of several different user controls
    > according to what is selected in the tree control. Now, I
    > can do this by placing all of my different user controls
    > on the form and then use .Show() and .Hide() on the
    > controls. However, I do not fancy this technique, Isn't
    > there a more elegant way of doing this.
    >
    > Another thing, If I instantiate these user controls
    > dynamically and place them on the form, should they be
    > placed on a panel?. Where should I store the reference to
    > the user control.
    >
    > Thank you in advance.
    > Best regards Jesper.[/color]


    Comment

    • Noah Coad [MVP .NET/C#]

      #3
      Re: Dynamic views

      Hey Jesper,

      I do this exact same thing in several of my programs. There is a list of
      'commands', each has its own GUI interface so there is a spot where the
      correct control plugs in. Here are some things to consider:

      1. It would be a good idea, but not required, to make one UserControl
      control that is a basic version of the plug-in control. Then the specific
      plug-ins can all be extended from your 'template' instead of UserControl.
      This gives you more control over how they look and interact.

      2. Yes, put a panel where you want the controls to go, it makes things a
      little easier. Let's call it 'pnlHost'. All you really need to do is look
      at the Windows Designer Generate Code to see how controls are added via
      code. I'll give you what you need here.

      private void ShowControl(Use rControl c)
      {
      pnlHost.Control s.Clear(); // Remove any current controls in the panel
      pnlHost.Control s.Add(c); // Put the special control in the host panel
      c.Dock = DockStyle.Fill; // Make the control fill the host panel
      }

      Then say you have a custom control called "PageSettin gs", you want to show
      it in the host panel, just call: ShowControl(new PageSettings()) ;

      That's practically all there is to it!

      Good luck!

      -Noah Coad
      Microsoft MVP & MCP [.NET/C#]



      "Jesper DK" <jeodni@hotmail .com> wrote in message
      news:033a01c357 a6$9d3a57e0$a50 1280a@phx.gbl.. .[color=blue]
      > Hi,
      >
      > I'm writing a windows explorer like application. The GUI
      > is divided by a vertical splitter. To the left I have a
      > tree control. To the right of the splitter I would like
      > to display one of several different user controls
      > according to what is selected in the tree control. Now, I
      > can do this by placing all of my different user controls
      > on the form and then use .Show() and .Hide() on the
      > controls. However, I do not fancy this technique, Isn't
      > there a more elegant way of doing this.
      >
      > Another thing, If I instantiate these user controls
      > dynamically and place them on the form, should they be
      > placed on a panel?. Where should I store the reference to
      > the user control.
      >
      > Thank you in advance.
      > Best regards Jesper.[/color]


      Comment

      • Jesper DK

        #4
        Re: Dynamic views

        Thanks Noah

        Could you clarify point 1. Provide a link to a sample
        perhaps. I would like to learn to do it right.

        Thanks and best regards.
        Jesper
        [color=blue]
        >-----Original Message-----
        >Hey Jesper,
        >
        >I do this exact same thing in several of my programs.[/color]
        There is a list of[color=blue]
        >'commands', each has its own GUI interface so there is a[/color]
        spot where the[color=blue]
        >correct control plugs in. Here are some things to[/color]
        consider:[color=blue]
        >
        >1. It would be a good idea, but not required, to make[/color]
        one UserControl[color=blue]
        >control that is a basic version of the plug-in control.[/color]
        Then the specific[color=blue]
        >plug-ins can all be extended from your 'template'[/color]
        instead of UserControl.[color=blue]
        >This gives you more control over how they look and[/color]
        interact.[color=blue]
        >
        >2. Yes, put a panel where you want the controls to go,[/color]
        it makes things a[color=blue]
        >little easier. Let's call it 'pnlHost'. All you really[/color]
        need to do is look[color=blue]
        >at the Windows Designer Generate Code to see how[/color]
        controls are added via[color=blue]
        >code. I'll give you what you need here.
        >
        >private void ShowControl(Use rControl c)
        >{
        > pnlHost.Control s.Clear(); // Remove any current[/color]
        controls in the panel[color=blue]
        > pnlHost.Control s.Add(c); // Put the special[/color]
        control in the host panel[color=blue]
        > c.Dock = DockStyle.Fill; // Make the control fill[/color]
        the host panel[color=blue]
        >}
        >
        >Then say you have a custom control[/color]
        called "PageSettin gs", you want to show[color=blue]
        >it in the host panel, just call: ShowControl(new[/color]
        PageSettings()) ;[color=blue]
        >
        >That's practically all there is to it!
        >
        >Good luck!
        >
        >-Noah Coad
        > Microsoft MVP & MCP [.NET/C#]
        >
        >
        >
        >"Jesper DK" <jeodni@hotmail .com> wrote in message
        >news:033a01c35 7a6$9d3a57e0$a5 01280a@phx.gbl. ..[color=green]
        >> Hi,
        >>
        >> I'm writing a windows explorer like application. The[/color][/color]
        GUI[color=blue][color=green]
        >> is divided by a vertical splitter. To the left I have a
        >> tree control. To the right of the splitter I would like
        >> to display one of several different user controls
        >> according to what is selected in the tree control.[/color][/color]
        Now, I[color=blue][color=green]
        >> can do this by placing all of my different user[/color][/color]
        controls[color=blue][color=green]
        >> on the form and then use .Show() and .Hide() on the
        >> controls. However, I do not fancy this technique, Isn't
        >> there a more elegant way of doing this.
        >>
        >> Another thing, If I instantiate these user controls
        >> dynamically and place them on the form, should they be
        >> placed on a panel?. Where should I store the reference[/color][/color]
        to[color=blue][color=green]
        >> the user control.
        >>
        >> Thank you in advance.
        >> Best regards Jesper.[/color]
        >
        >
        >.
        >[/color]

        Comment

        • Jesper DK

          #5
          Re: Dynamic views

          Thanks Noah

          Could you clarify point 1. Provide a link to a sample
          perhaps. I would like to learn to do it right.

          Thanks and best regards.
          Jesper
          [color=blue]
          >-----Original Message-----
          >Hey Jesper,
          >
          >I do this exact same thing in several of my programs.[/color]
          There is a list of[color=blue]
          >'commands', each has its own GUI interface so there is a[/color]
          spot where the[color=blue]
          >correct control plugs in. Here are some things to[/color]
          consider:[color=blue]
          >
          >1. It would be a good idea, but not required, to make[/color]
          one UserControl[color=blue]
          >control that is a basic version of the plug-in control.[/color]
          Then the specific[color=blue]
          >plug-ins can all be extended from your 'template'[/color]
          instead of UserControl.[color=blue]
          >This gives you more control over how they look and[/color]
          interact.[color=blue]
          >
          >2. Yes, put a panel where you want the controls to go,[/color]
          it makes things a[color=blue]
          >little easier. Let's call it 'pnlHost'. All you really[/color]
          need to do is look[color=blue]
          >at the Windows Designer Generate Code to see how[/color]
          controls are added via[color=blue]
          >code. I'll give you what you need here.
          >
          >private void ShowControl(Use rControl c)
          >{
          > pnlHost.Control s.Clear(); // Remove any current[/color]
          controls in the panel[color=blue]
          > pnlHost.Control s.Add(c); // Put the special[/color]
          control in the host panel[color=blue]
          > c.Dock = DockStyle.Fill; // Make the control fill[/color]
          the host panel[color=blue]
          >}
          >
          >Then say you have a custom control[/color]
          called "PageSettin gs", you want to show[color=blue]
          >it in the host panel, just call: ShowControl(new[/color]
          PageSettings()) ;[color=blue]
          >
          >That's practically all there is to it!
          >
          >Good luck!
          >
          >-Noah Coad
          > Microsoft MVP & MCP [.NET/C#]
          >
          >
          >
          >"Jesper DK" <jeodni@hotmail .com> wrote in message
          >news:033a01c35 7a6$9d3a57e0$a5 01280a@phx.gbl. ..[color=green]
          >> Hi,
          >>
          >> I'm writing a windows explorer like application. The[/color][/color]
          GUI[color=blue][color=green]
          >> is divided by a vertical splitter. To the left I have a
          >> tree control. To the right of the splitter I would like
          >> to display one of several different user controls
          >> according to what is selected in the tree control.[/color][/color]
          Now, I[color=blue][color=green]
          >> can do this by placing all of my different user[/color][/color]
          controls[color=blue][color=green]
          >> on the form and then use .Show() and .Hide() on the
          >> controls. However, I do not fancy this technique, Isn't
          >> there a more elegant way of doing this.
          >>
          >> Another thing, If I instantiate these user controls
          >> dynamically and place them on the form, should they be
          >> placed on a panel?. Where should I store the reference[/color][/color]
          to[color=blue][color=green]
          >> the user control.
          >>
          >> Thank you in advance.
          >> Best regards Jesper.[/color]
          >
          >
          >.
          >[/color]

          Comment

          Working...