CBComponents.HeaderTableLayoutPanel

TableLayoutPanel with highlighted header


Keywords
visual-studio, csharp, winforms, winforms-controls, library, controls, panel, tablelayout, windows, layout-engine, layouts, programming, visualisation, visual-studio-code, databases, free
License
MIT
Install
Install-Package CBComponents.HeaderTableLayoutPanel -Version 1.2.6307.23101

Documentation

Problem

There are a lot of panels for grouping the controls in WinForms. The best one of them is TableLayoutPanel, especially for grouping controls, that are using for editing data. Unfortunately, this panel does not show the header. This necessity appears when there are different kinds of editing controls on the same Windows form.

Solution

It can be solved by GroupBox and TableLayoutPanel. This solution is easy, but may look unpleasant. Another possibility is using Label control in first row of TableLayoutPanel. This solution may be uncomfortable.

I prefer to make inherited panel from TableLayoutPanel with all necessary functions.

How It works

TableLayoutPanel with highlighted header called HeaderTableLayoutPanel is simple, useful, and cute. This control may show the header in a number of different ways:

alt tag

The HeaderTableLayoutPanel implements just three properties:

  • CaptionText - string property that contains a text for showing. If this property is string.Empty or null then the header will not be shown
  • CaptionStyle - this is enum (HighlightCaptionStyle) property that points a drawing style. It can be: ForeColor, HighlightColor, HighlightStyle, NavisionAxaptaStyle, GroupBoxStyle (see the image above)
  • CaptionLineWidth - byte property that points the width of header's line (0 - the line will not be shown)

Be aware of CaptionLineWidth. If CaptionStyle = HighlightCaptionStyle.HighlightStyle, then two lines with Width = CaptionLineWidth will be shown, one will be above the Header and the second one will be below the header. For CaptionStyle = HighlightCaptionStyle.GroupBoxStyle this property does not do anything.

Screens

alt tag

alt tag

alt tag

How to use it

The following example explains the procedure to create a new HeaderTableLayoutPanel:

using CBComponents;
...
var headerTableLayoutPanel = new HeaderTableLayoutPanel()
{
  CaptionText = "Preferred text for header",
  CaptionStyle = HeaderTableLayoutPanel.HighlightCaptionStyle.NavisionAxaptaStyle,
  CaptionLineWidth = 2  
};
this.Controls.Add(headerTableLayoutPanel1);

To install HeaderTableLayoutPanel, run the following command in the Package Manager Console:

PM> Install-Package CBComponents.HeaderTableLayoutPanel 

Alternative option: download compiled library and examples.

Supported .NET Frameworks

HeaderTableLayoutPanel inherits from TableLayoutPanel, which was implemented in Microsoft .NET Framework 3.5. In general HeaderTableLayoutPanel does not use any special requirements. It can be compiled on any Microsoft .NET Framework platform (including the .NET Framework 3.5 client profile).

Contacts

I would appreciate hearing your opinion on this. If you have any questions, please feel free to contact me by email: radu.martin@hotmail.com

Please, support the author

Donate