Drawing text vertically

Is there a way to draw a text that is turned 90 degrees clockwise so that the text will be shown vertically?

This code in a Canvas’s Paint event handler will draw text rotated 90 degress:

Dim s as New StringShape s.Text = "Hello World" s.TextFont = "Helvetica" s.Bold = True s.Rotation = 3.14159/2 g.DrawObject(s)

Oh. I did not know there was StringShape class. Thank you for the help.

Paul,

I tried your code and it works fine. However my Canvas control is too small. Even when I resize it on the handles, or put a width / height value in the open event handler of the window for the Canvas it is still too small. Only the word “World is showing”.

Any idea what goes wrong here? I have this when using a canvas in other applications too.

Thank you very much for your advice and your code works perfectly.

Have a nice day.

Chris

You just need to adjust its position to start it further down on the Canvas:

Dim s As New StringShape s.Text = "Hello World" s.TextFont = "Helvetica" s.Bold = True s.Rotation = 3.14159/2 s.Y = 100 // Start down further so entire text fits g.DrawObject(s)

Hello Paul,

Thank you very much for your fast reply which is very much appreciated.

Indeed by placing the words further down both words are showing.

Wish you a very nice day.

Greetings,

Chris

This is an antique posting… but it is relavant to my question :slight_smile:

how do you insure a rotated string is CENTERED between two vertical points?

I have a rectangle (graphAREA) and I wish to draw a string rotated 270deg along the left edge, centered between the top and bottom

// font, size and color have been assigned to 'g'
// graphArea is the rect object
y=graphArea.top+((graphArea.height-g.Stringwidth(s))/2)
//
Dim ss As New StringShape
ss.Text = s
ss.x = 5+g.TextAscent
ss.y = y
ss.TextFont = g.textfont
ss.TextSize = g.textsize
ss.Rotation = -3.14159/2

g.DrawObject(ss)
g.drawline ss.x,ss.y,graphAREA.Center.x,grapharea.center.y

I was expecting the line in the last statement to be horizontal, but the “y” point and text is slightly above
and it has to be calcualted, as “S” could be “anything”

if you want the line to be horizontal shouldn’t the line read something like

       g.drawline ss.x,ss.y,ss.x + graphArea.Width,ss.y

so the start is at the center where you rotated the text around and the end is just some distance away along the x axis but at the same y

here that gives a perfectly horizontal line

  1. create new desktop project
  2. add canvas to window1 and size it up to mostly fill the window layout
  3. name it “grapharea” - yeah I realize this isn’t quite the same as what you’re doing but it serves the purpose
  4. add the paint event to the canvas
  5. paste in
Dim s As String = "something"

// font, size and color have been assigned to 'g'
// graphArea is the rect object
dim y as integer = graphArea.top+((graphArea.height-g.Stringwidth(s))/2)
//
Dim ss As New StringShape
ss.Text = s
ss.x = 5+g.TextAscent
ss.y = y
ss.TextFont = g.textfont
ss.TextSize = g.textsize
ss.Rotation = -3.14159/2

g.DrawObject(ss)

g.drawline ss.x,ss.y,ss.x + graphArea.Width,ss.y
  1. run

Norman… you missed my point… it is not a matter of MAKING the line horizontal… its a matter of positioning the text so that IT is centered… which right now it is NOT…

so to rephrase my question…
What is wrong with my calculation of “Y” that causes the text to NOT be centered between the top and bottom bounds of graphAREA?

You’re right
That wasnt clear at all

y should be

dim y as integer = graphArea.top+(graphArea.height/2)

since string shapes rotate about their midpoint
you dont need to calculate a midpoint

Dim x As Integer
Dim y As Integer

y = g.height / 2
g.drawline 0, y, g.width, y

Dim s As String = "something a lot longer"

//
Dim ss As New StringShape
ss.Text = s
ss.x = 5+g.TextAscent
ss.y = y
ss.TextFont = g.textfont
ss.TextSize = g.textsize
ss.Rotation = -3.14159/2

g.DrawObject(ss)

Dave, it may be worthwhile to post an image of what you are getting vs what you expect to get.

Code is one thing, sometimes an image makes things clearer.

Norman… that was it… thanks… I would mark it as “the answer”, but the forum is not giving me that option this morning