Version

Determine the Current Style

This topic discusses the procedure for gathering all style information applied to text, if you need to determine specific styles, see Determining if Text is in a Specific Format.

There will be times when you need to know what style is currently applied to text. You can do this by invoking the GetCurrentStyle method. This method returns a string of style information. Each style sub-attribute is separated by a semi-colon (;), making it easy to split if you needed an array of styles. See Clearing Specific Styles from Formatted Text for more information on the ClearStyleAttributes method which handles arrays of style information.

The following code demonstrates how to retrieve the style that is currently applied to the selected text and display it in a message box from a button click.

determine the current style of text in ultraformattedtexteditor

In Visual Basic:

Private Sub btnGetStyle_Click(ByVal sender As System.Object,_
  ByVal e As System.EventArgs) Handles btnGetStyle.Click
	If Me.UltraFormattedTextEditor1.EditInfo.GetCurrentStyle().ToString() <> "" Then
		MessageBox.Show("The currently applied style is:" & _
	  	  ControlChars.Lf + ControlChars.Lf & _
		Me.UltraFormattedTextEditor1.EditInfo.GetCurrentStyle().ToString())
	Else : MessageBox.Show("No style applied to selected text")
	End If
End Sub

In C#:

private void btnGetStyle_Click(object sender, EventArgs e)
{
	if(this.ultraFormattedTextEditor1.EditInfo.GetCurrentStyle().ToString() != "")
	{
		MessageBox.Show("The currently applied style is:\n\n" +
		  this.ultraFormattedTextEditor1.EditInfo.GetCurrentStyle().ToString());
	}
	else MessageBox.Show("No style applied to selected text");
}