# Drawing text vertically

**URL:** <https://forum.xojo.com/t/drawing-text-vertically/11659>\
**Category:** General\
**Created:** [October 15, 2013, 3:48pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659 "2013-10-15T15:48:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dong\_Kyun\_Ham](https://forum.xojo.com/user_avatar/forum.xojo.com/dong_kyun_ham/32/550_2.png) [@Dong\_Kyun\_Ham](https://forum.xojo.com/u/Dong_Kyun_Ham)\
**Post date:** [October 15, 2013, 3:48pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/1 "2013-10-15T15:48:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [October 15, 2013, 3:55pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/2 "2013-10-15T15:55:06Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![Dong\_Kyun\_Ham](https://forum.xojo.com/user_avatar/forum.xojo.com/dong_kyun_ham/32/550_2.png) [@Dong\_Kyun\_Ham](https://forum.xojo.com/u/Dong_Kyun_Ham)\
**Post date:** [October 15, 2013, 3:57pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/3 "2013-10-15T15:57:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Verberne](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_verberne/32/453_2.png) [@Chris\_Verberne](https://forum.xojo.com/u/Chris_Verberne)\
**Post date:** [October 15, 2013, 5:50pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/4 "2013-10-15T17:50:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [October 15, 2013, 6:17pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/5 "2013-10-15T18:17:46Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![Chris\_Verberne](https://forum.xojo.com/user_avatar/forum.xojo.com/chris_verberne/32/453_2.png) [@Chris\_Verberne](https://forum.xojo.com/u/Chris_Verberne)\
**Post date:** [October 15, 2013, 6:23pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/6 "2013-10-15T18:23:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 29, 2017, 2:39am UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/7 "2017-07-29T02:39:03Z")

</div>

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

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

```auto
// 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”

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [July 29, 2017, 3:26am UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/8 "2017-07-29T03:26:59Z")

</div>

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

```auto
       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

```auto
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

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 29, 2017, 5:18am UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/9 "2017-07-29T05:18:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [July 29, 2017, 1:19pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/10 "2017-07-29T13:19:56Z")

</div>

You’re right  
That wasnt clear at all

y should be

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

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Steve\_Kelepouris](https://forum.xojo.com/user_avatar/forum.xojo.com/steve_kelepouris/32/13856_2.png) [@Steve\_Kelepouris](https://forum.xojo.com/u/Steve_Kelepouris)\
**Post date:** [July 29, 2017, 1:20pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/11 "2017-07-29T13:20:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 29, 2017, 1:27pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/12 "2017-07-29T13:27:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 4:53pm UTC](https://forum.xojo.com/t/drawing-text-vertically/11659/13 "2020-10-29T16:53:55Z")

</div>


