autoexpand text in canvas

I want to have a text that expands himself until reaches 80% of window with or 10% of windows height (with canvas dimensions adapting the the text size)
I put the following code insite the canvas paint event

dim i as integer
g.TextSize = i
g.DrawString(win.textfield1.text, 0, 15)
me.width =g.StringWidth (win.TextField1.Text)
me.height = g.StringHeight(win.TextField1.Text, me.width)+15

loop until me.width>=win.width80/100 or me.height>=win.height10/100[/code]

it was working fine until i decided to add the do-loop circuit to create the “auto-expand” system but now it’s horrible
it flickers and it just wont work anymore.
How can I fix it ?

Please place

 g.DrawString(win.textfield1.text, 0, 15)

behind the loop.

not working, it flickers continuosly and it wont change size or anything :frowning:

I belive you have to put g.DrawString(…) after you have set me.width and me.height

Horacio, does setting the DoubleBuffer property of the Canvas to ON, make any difference with the flickering?

freezes the whole thing and I had to restart ;-(

Hmmm, that is strange, what OS are you using?

Windows 7. Why? does it work on yr computer ? here it’s a mess.
I suspect there must be something also about the order of wich events are called that I still have difficulties to master and understand
(paint within canvas etc etc)

As a sidenote. Wouldn’t it be better to put most of this stuff into a timer to have more control over the speed of the animation?

No because i dont want to animate anything. Actually if the transformation was instant it would be a lot better

But what is the Loop good for then?
Why not just resize the Text and the Canvas if the Window resizes or has been resized?
Couldn’t you just invalidate the Canvas when the resizing and/or resized event of the Window fires and do the Paint then?

Because I can’t know at what size the canvas and text will need to be resized.
The text string given changes at runtime so there is no way I can predict at design time the needed dimensions

increase size until it fits 80% of window

Wouldn’t the “me.width=…” line call a refresh, which will trigger a new paint event, in which you set me.width again…? Just a guess.

You can try to store the ew width of the canvas in a variable an apply it to the canvas ouside the loop.


But you could get the current StringWidth in relation to the Windows.Width and scale accordingly, or? :slight_smile:

[quote=122131:@Julen Ibarretxe Uriguen]Wouldn’t the “me.width=…” line call a refresh, which will trigger a new paint event, in which you set me.width again…? Just a guess.

yes I’m afraid something similar is happening. this would explain all the flickering and freezings…
jesus christ I love Xojo but I miss so much auto-sizing properties from VB6…

Is this something similar to what you want to achieve (paste the code in your Paint event of the canvas)?

[code] Dim s As String

s = “Some text to scale”

g.TextUnit = FontUnits.Pixel
g.TextSize = (Canvas1.Width * 1.8) / s.Len
g.DrawString(“Some animated text”, 0, 60)[/code]

This will size the text relative to the Canvas size.


  Dim s As String
  s = "Some text to scale"
  g.TextUnit = FontUnits.Pixel
  g.TextSize = (Canvas1.Width * 1.8) / s.Len
  g.DrawString(s, 0, 60)

thanks Alwyin, we are getting closer to the solution now…it’s ok for the width now I have to fix the height

OK here we go:

Under window resized event put:


Under canvas paint put:

dim s as string s="autosize this !" g.Bold=true g.TextUnit = FontUnits.Pixel g.TextSize =win.canvas.height g.DrawString(s,me.width/2- g.stringwidth(s)/2, g.textsize-10 )

Peace out !