Resize Text to Fit Canvas?

How do I dynamically resize text drawn on a canvas using DrawString knowing the fixed width of the canvas? What’s the formula for that? I’d like to resize the text as the string grows longer to be the best fit for the canvas. Thanks!

Use Graphics.StringWidth to see if the string will fit at its current size. This short example in the Paint event displays text at the largest font size so that it fits on one line, depending on the size of the Canvas:

  Const kText As String = "This is some sample text to display in the Canvas."
  g.TextSize = 100
  While g.StringWidth(kText) > g.Width
    g.TextSize = g.TextSize - 1
  g.DrawString(kText, 0, g.Height / 2)

Cool! Thanks!!!