Winforms Design Time support: exposing sub designers

When writing a UserControl, it is often desired to expose one or more of the sub-controls design-time support to the user of your control. It is reasonably straight forward to do, and here is a rundown of how: We start off with our UserControl, in this case the imaginatively named TestControl: The code behind looks like this: [Designer(typeof(TestControlDesigner))] public partial class TestControl : UserControl { public TestControl() { InitializeComponent(); } [DesignerSerializationVisibility(DesignerSerializationVisibility....

October 29, 2012 · 2 min

Databinding to a DataGridView - The order of columns

A while ago I was writing a small history grid in one of our applications at work. It has a single HistoryItem object, which is fairly straightforward, something like this: Class HistoryItem { public int ID { get{ return _id; } } public DateTime CreateDate { get { return _createDate; } } public String Creator { get { return _creatorName; } } public String Note { get { return _note; } } } This was populated into a List<HistoryItem> and bound to the DataGridView directly:...

October 20, 2010 · 2 min

Microcontrollers for MenuItems

I have been working my way through Jeremy Miller’s excellent Build Your Own CAB Series (which would be even better if he felt like finishing!) and was very interested by the article on controlling menus with Microcontrollers. After reading it and writing a version of it myself, I came to the conclusion that some parts of it seem to be wrong. All of the permissioning is done based on the menu items which fire ICommands, and several menu items could use the same ICommand....

May 29, 2009 · 5 min

Creating Non resizable controls

A control I was recently developing required being non-resizable when on the form. When the application is running, this would be easy enough, just set its AutoSize property to False, and don’t dock the control. However, this leaves the problem of resizing in the designer. You could override the resize event of the control, but for reasons outlined earlier, such as flickering, I decided against this. Somewhere on the internet (where else…?...

April 13, 2008 · 2 min

VB.NET &amp; C# Fixed height User Controls

Another problem I came across recently was fixed height user controls. Someone at work had created a fixed height user control, by putting the following code in the paint event: Me.Width = 20 Now while for the majority of cases this works, it doesn’t if you dock the control to the left or right of the form, as each time the Layout Engine tries to stick the top of the control to the top of the parent and the bottom of the control to the bottom of the parent, it fires the Paint() event....

March 29, 2008 · 2 min