Results 1 to 10 of 10

Thread: [RESOLVED] [2005] Display Vertical Text in a label ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    74

    Resolved [RESOLVED] [2005] Display Vertical Text in a label ?

    I've searched for vertical text, but was unable to find an answer on how to display vertical text in a label; eventhough there is an indication that it can be done.
    I tried to use the following sub but all I can get to display a emptyness.

    VB Code:
    1. Public Sub DrawYAxis()
    2.         Dim bm As Bitmap = New Bitmap(30, 50)
    3.         Dim g As Graphics = Graphics.FromImage(bm) 'Graphics object created from bitmap
    4.         Dim drawFont As New Font("Arial", 8)
    5.         Dim BlackBrush As New SolidBrush(Color.Black)
    6.         Dim What As String = "Y Axis"
    7.         g.DrawString(What, drawFont, BlackBrush, bm.Height, bm.Width)
    8.         g.TranslateTransform(CSng(bm.Width / 2), CSng(bm.Height / 2))
    9.         g.RotateTransform(90)
    10.         YAxisLabel.Image = bm
    11.         g.Dispose()
    12.     End Sub

    any guide to the blind will be appreciated! Thanks.

  2. #2
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2005] Display Vertical Text in a label ?

    You could sort the label into an array then display 1 letter with an
    VB Code:
    1. Environment.Newline
    in between.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    74

    Re: [2005] Display Vertical Text in a label ?

    Thanks. However, what I want to do is have the Y Axis displayed vertically along the Y axis of a graph. This will also be used to display other text non-horizontally. I've been searching the web, but so far no one has come close the actually showing how to do what i need (at lease I can't figure it out. What is throwing me off is trying to create a graphics object from a label. It does not have to be a label; a picturebox of panel will also work.

  4. #4
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2005] Display Vertical Text in a label ?

    VB Code:
    1. Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Label1.Text = "H" & Environment.NewLine & "i" & Environment.NewLine & Environment.NewLine _
    3.         & "T" & Environment.NewLine & "h" & Environment.NewLine & "e" & Environment.NewLine & _
    4.         "r" & Environment.NewLine & "e"
    5.     End Sub

    Will display "Hi There" downward.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    74

    Re: [2005] Display Vertical Text in a label ?

    Thanks, francisstokes, for your help. I don't want the text to read vertically one letter at a time, but the actually be sideways, as if the page was turned. I do not have a image to show you. I want the X Axis to be view horizontally along the top of the grid, and the Y Axis to be view turned 90 degrees along the left edge of the grid.

    jmcilhinney, in another thread indicated that this was posible.

  6. #6
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2005] Display Vertical Text in a label ?

    Sorry i understand what you mean now. Does it have to be a label?

  7. #7
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: [2005] Display Vertical Text in a label ?

    Working with RotateTransform is a pain in the neck. YOu have to set the rotate before you do the drawing, and then it wacks up the X and Y coordinates, since you have to imagine them all rotated.

    I made a picturebox instead of a label, and this worked..
    VB Code:
    1. Public Sub DrawYAxis()
    2.         Dim bm As Bitmap = New Bitmap(300, 500)
    3.         Dim g As Graphics = Graphics.FromImage(bm) 'Graphics object created from bitmap
    4.         Dim drawFont As New Font("Arial", 12)
    5.         Dim BlackBrush As New SolidBrush(Color.Black)
    6.         Dim What As String = "Y Axis"
    7.         g.RotateTransform(90)
    8.         'g.TranslateTransform(CSng(bm.Width / 2), CSng(bm.Height / 2)) 'I couldn't get this to work upside down because I didn't feel like playing with the math all day :)
    9.         g.DrawString(What, drawFont, BlackBrush, 0, -20)
    10.         PictureBox1.Image = bm
    11.         g.Dispose()
    12.     End Sub
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    74

    Re: [2005] Display Vertical Text in a label ?

    No, it does not need to be a label. I came across this sub, I found in "Bobo Color Picker" from PSC, that I incorporated into the program. It is close to what I want, except that I can't control the faceing of the text.
    VB Code:
    1. Public Sub DrawYAxis(ByVal TargetBox As PictureBox, ByVal lblText As String)
    2.         'Printing text vertically
    3.         Dim drawFont As New Font("Arial", 10)
    4.         Dim TextBrush As New SolidBrush(System.Drawing.SystemColors.MenuText)
    5.         TargetBox.Image = New Bitmap(TargetBox.Width, TargetBox.Height)
    6.         Dim g As Graphics = Graphics.FromImage(TargetBox.Image)
    7.         Dim sFormat As New StringFormat
    8.         sFormat.FormatFlags = StringFormatFlags.DirectionVertical
    9.         g.DrawString(lblText, drawFont, TextBrush, 0, 0, sFormat)
    10.         TargetBox.Invalidate()
    11.         TextBrush.Dispose()
    12.         g.Dispose()
    13.         sFormat.Dispose()
    14.     End Sub

    I know that there must be a better way to control the direction of text.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Display Vertical Text in a label ?

    The ElementsEx library in my signature has a RotatedLabel control that allows you to place text at any angle as simply as adding a regular Label.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    74

    Re: [2005] Display Vertical Text in a label ?

    Thanks, jmcilhinney. I will check it out.
    This revised code does what I want:
    VB Code:
    1. Public Sub DrawYAxis(ByVal TargetBox As PictureBox, ByVal lblText As String)
    2.         'Printing text vertically
    3.         Dim drawFont As New Font("Arial", 10)
    4.         Dim TextBrush As New SolidBrush(System.Drawing.SystemColors.MenuText)
    5.         TargetBox.Image = New Bitmap(TargetBox.Width, TargetBox.Height)
    6.         Dim g As Graphics = Graphics.FromImage(TargetBox.Image)
    7.         g.TranslateTransform(0, TargetBox.Height) ' (0, textwidth)
    8.         'set the rotation angle for vertical text
    9.         g.RotateTransform(270)
    10.         g.DrawString(lblText, drawFont, TextBrush, 0, 0)
    11.         TargetBox.Invalidate()
    12.         TextBrush.Dispose()
    13.         g.Dispose()
    14.     End Sub

    Thanks all the the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width