Results 1 to 6 of 6

Thread: [2008] Help me with a concept - adding controls to usercontrol

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    [2008] Help me with a concept - adding controls to usercontrol

    Hi,

    I am trying to create a UserControl that behaves like the Options screen in the visual studio 2008 IDE (and many other programs).

    Basically instead of Tabs listing the 'subjects', you have a list to the left side which can contain the subject titles and/or images (a listview). Then on the right there is some room for panels (let's call them Pages) which get hidden and unhidden whenever required. These pages would contain the 'options controls' (like checkboxes, textboxes, comboboxes etc..).


    Now I'm looking for a smart way to make the user of my usercontrol able to add these controls graphically. Because the Pages (panels) get added via code (otherwise you would still have to do most of the work yourself which would kind of defeat the point of my control) you cannot simply drag the required controls on those pages in the designer.

    The ideal way would be to make something where the user can select "Add Page" and a blank options page would pop up (much like the VS Form designer) allowing him to put whatever controls on it they like.

    I realize that this is probably way too advanced or even impossible so now I'm looking for a new way to do this.


    Does anyone have any ideas?

    One idea I had is to present the user with a new blank Form on which he can put his controls, then after visual studio creates the required 'Designer.vb' file (in which the exact location and properties of the controls are stored) I 'copy/paste' this designer code to my panel code. So basically you transfer the controls from the Form designer to the panel (via code) and then the form can be deleted again...
    Again I doubt this is possible but you never know...

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Help me with a concept - adding controls to usercontrol

    Actually (why didn't I think of this?) it would be perfect if I could do it like the TabControl does it.

    You add a Page and it adds the page in the designer aswell, allowing you to place the controls on it like you would do with any other container...

    Is that possible?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Help me with a concept - adding controls to usercontrol

    The design-time behaviour of a control is determined by various things, all specified by attributes from the System.ComponentModel namespace. If you want your control to be able to be edited a special way in the designer then you have to create a custom designer for it and then specify that designer using the DesignerAttribute class. You might want to install .NET Reflector and take a look at the source for the TabControl class, then try to emulate it from there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Help me with a concept - adding controls to usercontrol

    Yes, I figured that out just now after downloading the source for a Custom TabControl, which did exactly what I wanted. Unfortunately it was written in C# and I'm finding it hard figuring out which parts of the code are relevant to me.

    I will try out the .NET Reflector and see where it gets me, but I'm afraid I'm going to have the same problem... Oh well, we'll see.

    Thanks!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Help me with a concept - adding controls to usercontrol

    If you have a compiled assembly then Reflector will decompile it to C# or VB, regardless of the original language of the source code. Remember that the whole Framework was written in C#.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Help me with a concept - adding controls to usercontrol

    Yeah I've noticed, that is awesome. What does Reflector actually show you? The 'source code' of the control?

    I'm just looking at the TabControl but I cannot find any Designer related code. I seem to remember (from the custom tabcontrol C# code) that there should be some <Designer(GetType ...)> 'tag' in front of the designer code, but I can't seem to find any of that. Is it maybe in any of the 'sub entries' of the TabControl entry (I'm talking about the 'entries' in the treeview in the .NET Reflector program)?
    If you happen to know where I can find it can you point me in the right direction?

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