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

Customized Text - Orientated Controls in C# - Part I (Label Control)

Rate me:
Please Sign up or sign in to vote.
4.89/5 (50 votes)
26 Sep 20042 min read 199.3K   14.4K   92   40
Label which can display text in any orientation and shape.

Sample Image - customtext.jpg

Introduction

There are many ways in which text can be displayed. But most common ways are showing it in the path of straight line, arc, and circle. The Label which comes with NET can only display the text in the path of a straight line. This control can do that in all the main three methods, with rotation angle. Also, text can be displayed in a direction which we are interested in.

How it Works

There are a few points we must take care about, before we write:

  1. Where we must write the character.
  2. Angle of the letter with the axis.
  3. Path of the string.
  4. Direction of the string.

According to our needs, we can override the control's OnPaint method and draw the text. We must draw the text on our own using Graphics object. It has very useful methods which can be used here. TranslateTransform and RotateTransform are the common methods used to achieve this task. TranslateTransform is used to move the text, where we want it to be displayed. The other method is to rotate the character to orientate it with center.

The control has three properties, which can be used:

  • TextOrientation

    How the text must be displayed. Three methods are supported in Label. They are Rotate, Arc and Circle. We can display it in a straight line with rotation. I mean, the text will be displayed in a straight path, but the text can be rotated in any angle we want. The other is Arc, in which we can display a text in arc shape. The last one is, displaying it in circular path.

  • TextDirection

    There are two ways, which direction we want to display text when we think about displaying it in arc's path or circular one. They are clockwise and anticlockwise.

  • RotationAngle

    Text can be rotated in any angle we like. This can be mostly done in straight line.

Summary

My plan is to write custom controls in which we can rotate the text. In future, according to the feedback I get from this, I will write more custom controls where we can do text oriented works.

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
Web Developer
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionconfuse to convert to vbnet Pin
Alvin Seliang13-Sep-20 4:02
Alvin Seliang13-Sep-20 4:02 
Praise* 5 * Stars Pin
David Kinney23-Nov-16 8:43
David Kinney23-Nov-16 8:43 
GeneralMy vote of 5 Pin
Metafunken23-Apr-14 20:30
Metafunken23-Apr-14 20:30 
QuestionMy Vote of 5 Pin
Metafunken23-Apr-14 20:29
Metafunken23-Apr-14 20:29 
QuestionOK, but what about printing? Pin
nikonation6-Feb-14 21:55
nikonation6-Feb-14 21:55 
GeneralMy vote of 5 Pin
Gopinaath Manokaran20-Feb-13 21:54
Gopinaath Manokaran20-Feb-13 21:54 
use of mathematical skill is outstanding
Questionalignment problem Pin
amolpbhavsar18-Oct-11 1:27
amolpbhavsar18-Oct-11 1:27 
GeneralText gets messed up when using it in other user control with scrollbox... Pin
Nicklez28-Feb-11 3:06
Nicklez28-Feb-11 3:06 
GeneralRe: Text gets messed up when using it in other user control with scrollbox... Pin
Steveproject25-Jun-11 1:32
Steveproject25-Jun-11 1:32 
GeneralWinCE Compact framework Pin
arunmuthu13-Oct-10 2:25
arunmuthu13-Oct-10 2:25 
GeneralThanks Pin
arapillai9-Nov-09 0:14
arapillai9-Nov-09 0:14 
GeneralSimple/Perfect. Thank you! Pin
Douglas Berry9-Oct-08 5:28
Douglas Berry9-Oct-08 5:28 
GeneralYes I love it. Pin
v# guy23-Jun-08 1:39
v# guy23-Jun-08 1:39 
GeneralRe: Yes I love it. Pin
Ahmad993-Sep-08 19:22
Ahmad993-Sep-08 19:22 
QuestionHow to modify this control for web forms. Pin
Ahmad994-Jun-08 3:01
Ahmad994-Jun-08 3:01 
AnswerRe: How to modify this control for web forms. Pin
Elliott Ortiz12-Oct-09 6:17
Elliott Ortiz12-Oct-09 6:17 
GeneralLabelled Textbox Pin
Chakreee8-Sep-06 4:00
Chakreee8-Sep-06 4:00 
Generalmake it support colors Pin
TheCardinal11-Aug-06 12:30
TheCardinal11-Aug-06 12:30 
GeneralI need rtf codes to include picture Pin
Anonymous10-Oct-05 8:55
Anonymous10-Oct-05 8:55 
QuestionGreat Control, but... Pin
lgbjr20-Sep-05 21:01
lgbjr20-Sep-05 21:01 
GeneralEntryPoint Question Pin
Anonymous11-Jun-05 6:39
Anonymous11-Jun-05 6:39 
GeneralI need help Pin
Tomek Frykas11-Jun-05 5:18
Tomek Frykas11-Jun-05 5:18 
GeneralProblems with alignement Pin
dscemama13-Apr-05 2:32
dscemama13-Apr-05 2:32 
GeneralRe: Problems with alignement Pin
dscemama13-Apr-05 3:13
dscemama13-Apr-05 3:13 
GeneralRe: Problems with alignement Pin
lowrider196815-Dec-05 2:36
lowrider196815-Dec-05 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.