<div class="meta" robots="noindex">

</div>

Method

# Graphics.StringWidth

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `Graphics.TextWidth<graphics.textwidth>` as a replacement.

</div>

## Description

Returns as a `Double</api/data_types/double>` the width of *Text* in points, based on the current text properties of the `Graphics</api/graphics/graphics>` object.

## Notes

To be precise, Graphics.StringWidth returns the width of the string's baseline, which is to say that it returns the position that the next character would be drawn at, if the string were to be extended. For example, if `Graphics.Bold<graphics.bold>` is `True</api/language/true>`, then each character would have a larger width when drawn, so Graphics.StringWidth will return a larger value than otherwise. On the other hand, if `Graphics.Italic<graphics.italic>` is `True</api/language/true>`, then the last character of the string would lean to the right when drawn, increasing the visual width of the string slightly. However, the baseline of the rendered string would not have changed, so Graphics.StringWidth will generally not return a different value in this case.

Graphics.StringWidth does not handle multiple lines in the way that one might expect. Essentially, the multi-line nature of the string is ignored, and newline sequences are treated as if they were space characters. For example, it returns the same value for the string "A B" as for the string "A"+EndOfLine+"B". To take multiple lines into account, you'll need to `String.Split<string.split>` the string into multiple lines yourself, and calculate the width of each line separately, handling leading or trailing whitespace in whatever way makes sense for your situation.

<div class="note">

<div class="title">

Note

</div>

Prior to version 2007 Release 2, <span class="title-ref">StringWidth</span> returned an `Integer</api/data_types/integer>`. Currently, only macOS supports fractional widths. In the future, fractional widths may be supported on other platforms.

</div>

## Sample code

This example creates a `Picture</api/graphics/picture>` and uses its Graphics object to calculate the <span class="title-ref">StringWidth</span> and display it in a TextField on a window:

``` xojo
Dim d As Double
Dim p As New Picture(100, 100, 32)
d = p.Graphics.StringWidth("Hello World!")
TextField1.Text = Str(d)
```

## Compatibility

All project types on all supported operating systems.
