Windows Develop Bookmark and Share   
 index > Windows Forms Designer > UserControl With Multiple Panels
 

UserControl With Multiple Panels

I have a usercontrol with some panels in it.A header and a content panel. I want that in the designer you can drop controls in one of them and not in other parts of the usercontrol.

I already have this.

Code Block

[Designer(typeof(MyControlDesigner))]

public partial class MyUserControl: UserControl

{

}

public class MyControlDesigner : System.Windows.Forms.Design.ControlDesigner

{

public override void Initialize(System.ComponentModel.IComponent component)

{

base.Initialize(component);

MyUserControluc = component as MyUserControl;

EnableDesignMode(uc.Content, "Content");

EnableDesignMode(uc.Header, "Header");

}

}

The problem with this code is that the panels are resizable in the designer (on the form where i dropped the uc), and i don't want that.

I also have the problem when i select the inner panel and i click the move icon on the top left visual studio crashes with this message. Object reference not set to an instance of an object.

Is this a good start for what i want or must i take another approach?

Edit:

i found this

Code Block

public override SelectionRules SelectionRules

{

get

{

return SelectionRules.None;

}

}

I could make a custom ControlDesigner for the panels with this SelectionRule. But whenyou select the panel you can see the properties in the properties window and you could still change the size there. So this is still not realy what i want.

It would be nice that the you can't select the panels so that there properties are not shown in the properties window.

KCSharp  Wednesday, November 14, 2007 12:15 PM

You cancreate a Property to override the Size propertyof the Panel andmake it un-browserable, then the Size propery will not be displayed on the PropertyGrid,something like this:

Code Block

Designer(typeof(MyPanelControlDesigner))]

public class MyPanel : Panel

{

public MyPanel()

{

this.BackColor = Color.Red;

}

[Browsable(false)]

public new Size Size

{

get { return base.Size; }

set { base.Size = value; }

}

}

public class MyPanelControlDesigner : System.Windows.Forms.Design.ControlDesigner

{

public override System.Windows.Forms.Design.SelectionRules SelectionRules

{

get

{

return System.Windows.Forms.Design.SelectionRules.None;

}

}

}

You cancreate a Property to override the Size propertyof the Panel andmake it un-browserable, then the Size propery will not be displayed on the PropertyGrid,something like this:

Code Block

Designer(typeof(MyPanelControlDesigner))]

public class MyPanel : Panel

{

public MyPanel()

{

this.BackColor = Color.Red;

}

[Browsable(false)]

public new Size Size

{

get { return base.Size; }

set { base.Size = value; }

}

}

public class MyPanelControlDesigner : System.Windows.Forms.Design.ControlDesigner

{

public override System.Windows.Forms.Design.SelectionRules SelectionRules

{

get

{

return System.Windows.Forms.Design.SelectionRules.None;

}

}

}

I made most of the properties that should not be changed not browsable.

So they are at least not visible in the designer anymore.

It's not really what i had in mind but it's good enough.

Thanks for the help

KCSharp  Thursday, November 22, 2007 7:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Override PaintValue on UITypeEditor
• UserControl, Inherited Control, Abstract class, (C#)
• windows form designer error:The class Settings can be designed, but is not the first class in the file...."
• How to change the look of the Caption Bar?
• Strange behaviour when changing language
• Visual studio designer error creating inherited form
• Using CodeDom to generate event handler??
• Mouse Cursor on UserControl in Design Mode
• Columns in DataGridView re-order themselves after build
• How to display SmartTags/DesignerVerbs in a home made DesignerHost