Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

Vertical Label - Vertical Text VB.NET

$
0
0
Hello all,

For I have some trouble to find out how to create a vertical label or vertical text in VB.NET myself, I would like to share my solution. WARNING: I know it can be done better - this solution is only for those, who are looking for something uncomplicated and fast!

The first thing is to realize, where do you want a label you want to rotate to be placed. A form itself, or panel? The object you want the label to be placed on is the object which you need to paint label.

CODE:
'Let´s say we want our Label1 to be placed on Panel1 and to be vertical.
Private Sub Panel1_Paint(ByVal sender as System.Object, ByVal e as System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawString(Me.Label1.Text,Me.Label1.Font,Brushes.Black,Me.Label1.Left,Me.label1.Top, New StringFormat(StringFormatFlags.DirectionVertical))
Me.Label1.Visible
End Sub

What does this code do? Just read the attributes of label, draw similar one at the same point (just vertical) and hide the original object. Be aware of the fact, that this solution is usefull only if there is no need to use label events. The new label is just drawing.

If you want to use a specific font:

declare it like this:
dim drawFont as new Font("Arial",8)

then use it instead me.label1.font


Details:
Me.Label1.Text - text of the original label
Me.Label1.Font - font of the original label - you can use newfont as well
,Brushes.Black - colour of text
,Me.Label1.Left - information about position of the original label (x-axis)
Me.label1.Top - information about position of the original label (y-axis)
New StringFormat(StringFormatFlags.DirectionVertical) - vertical text attribute


That is all. I apologize those who wanted something more sophisticated, but i find it really difficult to obtain at least this simple solution, so I wanted to share something that really works and it is easy for newbies (like me). If you feel like writing better solution, I would be very pleased.

Divisadero

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>