65.9K
CodeProject is changing. Read more.
Home

Vertical Label using Infragistics Controls

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.87/5 (6 votes)

Dec 20, 2013

CPOL
viewsIcon

14448

Vertical Label in C# Windows Forms without overriding OnPaint using Infragistics controls

Introduction

This tip describes how to create a vertical label control in C# Windows Forms using Infragistics' ultraGroupBox. This is actually a cheat method but we can achieve the vertical text without creating a new class and overriding OnPaint. It is only applicable to those who are using Infragistics controls. :(

Background

Today, I came across the situation where I need a vertical text in a Form and searched in net and got some solutions including this one , but I felt it is costly to create a class and overriding OnPaint and CreateParams for simply displaying a vertical text. So I used ultraGroupBox and modified few properties to bring vertical text both starting from top and bottom.

Using the Code

This is the designer generated code based on the properties we set them in the designer.

// ultraGroupBox1            
//             
appearance1.ForeColor = System.Drawing.Color.Red;            
this.ultraGroupBox1.Appearance = appearance1;            
this.ultraGroupBox1.BorderStyle = Infragistics.Win.Misc.GroupBoxBorderStyle.None;            
appearance2.BackColor = System.Drawing.Color.Khaki;            
appearance2.FontData.Name = "Verdana";            
appearance2.FontData.SizeInPoints = 10F;            
appearance2.ForeColor = System.Drawing.Color.Red;            
this.ultraGroupBox1.HeaderAppearance = appearance2;            
this.ultraGroupBox1.HeaderPosition = 
	Infragistics.Win.Misc.GroupBoxHeaderPosition.LeftOutsideBorder;            
this.ultraGroupBox1.Location = new System.Drawing.Point(73, 61);            
this.ultraGroupBox1.Name = "ultraGroupBox1";            
this.ultraGroupBox1.Size = new System.Drawing.Size(32, 216);            
this.ultraGroupBox1.TabIndex = 0;            
this.ultraGroupBox1.Text = "Vertical Text - BottomToTop";            
this.ultraGroupBox1.VerticalTextOrientation = 
	Infragistics.Win.Misc.GroupBoxVerticalTextOrientation.BottomToTop;
//             
// ultraGroupBox2            
//             
appearance3.ForeColor = System.Drawing.Color.Red;            
this.ultraGroupBox2.Appearance = appearance3;            
this.ultraGroupBox2.BorderStyle = Infragistics.Win.Misc.GroupBoxBorderStyle.None;            
appearance4.BackColor = System.Drawing.Color.Khaki;            
appearance4.FontData.Name = "Verdana";            
appearance4.FontData.SizeInPoints = 10F;            
appearance4.ForeColor = System.Drawing.Color.Red;            
this.ultraGroupBox2.HeaderAppearance = appearance4;            
this.ultraGroupBox2.HeaderPosition = 
	Infragistics.Win.Misc.GroupBoxHeaderPosition.LeftOutsideBorder;            
this.ultraGroupBox2.Location = new System.Drawing.Point(178, 61);            
this.ultraGroupBox2.Name = "ultraGroupBox2";            
this.ultraGroupBox2.Size = new System.Drawing.Size(32, 216);            
this.ultraGroupBox2.TabIndex = 1;            
this.ultraGroupBox2.Text = "Vertical Text - TopToBottom";            
this.ultraGroupBox2.VerticalTextOrientation = 
	Infragistics.Win.Misc.GroupBoxVerticalTextOrientation.TopToBottom; 

If HeaderPosition property is set to LeftOutsideBorder, we have achieved 50% , then BorderStyle = None will finish the work and resize the groupbox according to the size needed. VerticalTextOrientation property determines the TopToBottom or BottomToTop text orientation.

Though this is a very small work, I hope sure this will help somebody. :)