wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-dot-measuresinglelinestring-x28-system-dot-string-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-characterpropertiesbase-x29.md
Calculates the length of a formatted string.
Namespace : DevExpress.Xpf.RichEdit
Assembly : DevExpress.Xpf.RichEdit.v25.2.dll
NuGet Package : DevExpress.Wpf.RichEdit
public SizeF MeasureSingleLineString(
string text,
CharacterPropertiesBase properties
)
Public Function MeasureSingleLineString(
text As String,
properties As CharacterPropertiesBase
) As SizeF
| Name | Type | Description |
|---|---|---|
| text | String |
A string to measure.
| | properties | CharacterPropertiesBase |
A CharacterPropertiesBase interface specifying the format used to display a string.
|
| Type | Description |
|---|---|
| SizeF |
A SizeF object that is the rectangle required to display a string.
|
The following code snippet illustrates the use of a MeasureSingleLineString method, to calculate required size of a tab stop. The tab stop position is specified by the TabInfo.Position property and measured in units of a current document (Document.Unit value). To provide uniform tab stops for a certain number of characters, a monospaced font is selected as the default document font.
DevExpress.XtraRichEdit.API.Native.Document document = richEditControl1.Document;
SizeF tabSize = richEditControl1.MeasureSingleLineString(new String('w', 4), document.DefaultCharacterProperties);
DevExpress.XtraRichEdit.API.Native.TabInfoCollection tabs = document.Paragraphs[0].BeginUpdateTabs(true);
try
{
for (int i = 1; i <= 30; i++)
{
DevExpress.XtraRichEdit.API.Native.TabInfo tab = new DevExpress.XtraRichEdit.API.Native.TabInfo();
tab.Position = i * tabSize.Width;
tabs.Add(tab);
}
}
finally
{
document.Paragraphs[0].EndUpdateTabs(tabs);
}
Dim document As DevExpress.XtraRichEdit.API.Native.Document = richEditControl1.Document
Dim tabSize As SizeF = richEditControl1.MeasureSingleLineString(New String("w"c, 4), document.DefaultCharacterProperties)
Dim tabs As DevExpress.XtraRichEdit.API.Native.TabInfoCollection = document.Paragraphs(0).BeginUpdateTabs(True)
Try
For i As Integer = 1 To 30
Dim tab As New DevExpress.XtraRichEdit.API.Native.TabInfo()
tab.Position = i * tabSize.Width
tabs.Add(tab)
Next i
Finally
document.Paragraphs(0).EndUpdateTabs(tabs)
End Try
See Also