Example - Creating an Instance

ServerTextControl is a non-UI .NET component that can be initialized in all .NET based applications.

This example is part the Sample Explorer project which includes all samples in one. The sources for this sample project can be found here:

Language Project Location
C# %USERPROFILE%\Documents\TX Text Control 24.0.NET Server for ASP.NET\Samples\ASP.NET\CSharp\Sample Explorer\
VB.NET %USERPROFILE%\Documents\TX Text Control 24.0.NET Server for ASP.NET\Samples\ASP.NET\VB.NET\Sample Explorer\

You will find the source code and the ASPX page of this sample in the Solution structure tree under: Basics\create.aspx

Example description

1. Click the button "Create ServerTextControl" to create an instance of ServerTextControl.

On the button click event, a new ServerTextControl instance is created. Formatted text is inserted using the Selection object and saved as HTML which is returned to a DIV element.

[C#]
protected void Button1_Click(object sender, EventArgs e)
{
	// create a new instance of ServerTextControl
	using (TXTextControl.ServerTextControl tx =
		new TXTextControl.ServerTextControl())
	{
		// ServerTextControl must be "created"
		tx.Create();
		tx.Text = "TX Text Control .NET Server for ASP.NET\r\nThis HTML text " +
			"has been created by ServerTextControl at " +
			DateTime.Now.ToString() + ".";

		// create a new selection and apply some formatting
		TXTextControl.Selection selection = new TXTextControl.Selection(0, 15);
		selection.Bold = true;
		selection.ForeColor = Color.Red;

		// apply the selection to the ServerTextControl instance
		tx.Selection = selection;

		// save the content as HTML
		string sHTML;
		tx.Save(out sHTML, TXTextControl.StringStreamType.HTMLFormat);

		htmldiv.InnerHtml = sHTML;
	}
}
[Visual Basic]
Protected Sub Button1_Click(sender As Object, e As EventArgs)
	' create a new instance of ServerTextControl
	Using tx As New TXTextControl.ServerTextControl()
		' ServerTextControl must be "created"
		tx.Create()
		tx.Text = "TX Text Control .NET Server for ASP.NET" & _
			vbCr & vbLf & "This HTML text " + _
			"has been created by ServerTextControl at " + _
			DateTime.Now.ToString() + "."

		' create a new selection and apply some formatting
		Dim selection As New TXTextControl.Selection(0, 15)
		selection.Bold = True
		selection.ForeColor = Color.Red

		' apply the selection to the ServerTextControl instance
		tx.Selection = selection

		' save the content as HTML
		Dim sHTML As String
		tx.Save(sHTML, TXTextControl.StringStreamType.HTMLFormat)

		htmldiv.InnerHtml = sHTML
	End Using
End Sub