Prevent Winforms Designer from Generating Property Values for Inherited Controls

I should emphasize that this isn’t normally the way you do this, the [DefaultValue] attribute is normally the correct choice. But you are working with a property of type Color, it is not simple to write the attribute for that in a flexible way. The arguments you can pass to an attribute constructor can be … Read more

How to set text to a control from resource file in design time?

The designer only serializes string for Text property. You can not set the Text property to a resource value directly using designer. Even if you open the Form1.Designer.cs file and add a line to initialization to set the Text property to a resource value like Resource1.Key1, after first change in designer, the designer replace your … Read more

Custom Color Palette in Visual Studio Color Property Editor

The editor that helps you to pick color in visual studio is ColorEditor which doesn’t persists custom colors across different controls. To solve the problem, you should: Create a custom UITypeEditor based on ColorEditor Register the editor for type Color at visual studio startup Here is a detailed answer including codes which I used to … Read more

Show controls added programmatically in WinForms app in Design view?

Does the designer run my code? When a form shows in designer, the designer deserialize the code of your form (Form1.Designer.cs or first class in Form1.cs) and creates an instance of the base class of your form and deserialize InitializeComponent and creates controls that you declared in your class and set their properties. So the … Read more

UserControl with header and content – Allow dropping controls in content panel and Prevent dropping controls in header at design time

You should do the following : For your user control, you need to create a new designer which enables the inner panel on design-time by calling EnableDesignMode method. For the inner panel, you need to create a designer which disables moving, resizing and removes some properties from designer. You should register the designers. Example You … Read more

Displaying a collection of controls in Windows Forms

You can use either of these options: DataGridView (Example) You can use DataGridView to show multiple columns of different types, including TextBox, Label, CheckBox, ComboBox, Image, Button, Link. You also can customize appearance of the grid by custom painting or adding new custom column types. UserControl You can create a composite control or UserControl containing … Read more