Click here to Skip to main content
15,889,833 members
Articles / Programming Languages / C#
Article

GridPanel

Rate me:
Please Sign up or sign in to vote.
3.67/5 (12 votes)
22 May 2003 76.5K   1.2K   19  
Property-Grid layout control

Introduction

In many applications I use user interface controls, which provide property management functionality, similar to PropertyTab. The problem is that PropertyTab is not very useful, if properties are complex enough, custom controls required or additional activities needed. So I need an easy way to layout controls into one grid.

Background

GridPanel implements custom layout - it places contained controls into one grid. One column of the grid contains labels (names of appropriate controls), another column contains controls. Above is an example of the grid with three controls. All controls can be accessed through the Controls property and they appear in the grid in the same order as in the Controls list. The grid labels are drawn in the OnPaint() handler - they are not stored as Label instances.

Using the code

GridPanel layouts contained controls, which can be accessed through the Controls property. Developer needs to set the Name property for each control. Each contained control preserves its height and width (except the case, then the Anchor property is set to left and right). Below is code snippet for the example, captured in the picture.

C#
TextBox stext = new TextBox();
stext.Name = "Simple text";

TextBox mtext = new TextBox();
mtext.Name = "Complex text";
mtext.Multiline = true;
mtext.Anchor = AnchorStyles.Left|AnchorStyles.Right;
mtext.Height = stext.Height * 5;
mtext.ScrollBars = ScrollBars.Vertical;

ComboBox combo = new ComboBox();
combo.Name = "Drop down";
combo.DropDownStyle = ComboBoxStyle.DropDown;

GridPanel gp = new GridPanel(stext, mtext, combo);

History

  • 23 May 2003 - updated download

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --