property HTML.FormatSelection(Attribute as HTMLFormatEnum) as Variant
Formats the current selection.

TypeDescription
Attribute as HTMLFormatEnum A HTMLFormatEnum expression that specifies the attribute to be changed/queried
Variant A VARIANT expression that specifies the new value for requested attribute. The type of the VARIANT value is based on the Attribute as explained in HTMLFormatEnum type
The FormatSelection property formats the current selection. For instance, you can use the FormatSelection(exHTMLFormatBold) property to bold the current selection. The SelStart property returns or sets the starting point of text selected; indicates the position of the insertion point if no text is selected. Use the SelLength property to get the selection's length. The SelText property specifies the selected text.

The following samples formats programmatically  the selection:

VBA (MS Access, Excell...)

With HTML1
	.Text = "first line<br>second line<br>third line"
	.SelStart = .XYToPosition(0,1)
	.SelLength = 11
	.HideSelection = False
	.FormatSelection(1) = True
	.FormatSelection(8) = 1
	Debug.Print( .FormatSelection(1) )
	.SelStart = .XYToPosition(0,2)
	.SelLength = -1
	.FormatSelection(4) = True
	.FormatSelection(8) = 2
End With

VB6

With HTML1
	.Text = "first line<br>second line<br>third line"
	.SelStart = .XYToPosition(0,1)
	.SelLength = 11
	.HideSelection = False
	.FormatSelection(exHTMLFormatBold) = True
	.FormatSelection(exHTMLFormatAlign) = 1
	Debug.Print( .FormatSelection(exHTMLFormatBold) )
	.SelStart = .XYToPosition(0,2)
	.SelLength = -1
	.FormatSelection(exHTMLFormatUnderline) = True
	.FormatSelection(exHTMLFormatAlign) = 2
End With

VB.NET

With Exhtml1
	.Text = "first line<br>second line<br>third line"
	.SelStart = .get_XYToPosition(0,1)
	.SelLength = 11
	.HideSelection = False
	.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold,True)
	.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,1)
	Debug.Print( .get_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold) )
	.SelStart = .get_XYToPosition(0,2)
	.SelLength = -1
	.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatUnderline,True)
	.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,2)
End With

VB.NET for /COM

With AxHTML1
	.Text = "first line<br>second line<br>third line"
	.SelStart = .get_XYToPosition(0,1)
	.SelLength = 11
	.HideSelection = False
	.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold,True)
	.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,1)
	Debug.Print( .get_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold) )
	.SelStart = .get_XYToPosition(0,2)
	.SelLength = -1
	.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatUnderline,True)
	.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,2)
End With

C++

/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXHTMLLib' for the library: 'ExHTML 1.0 Control Library'

	#import <ExHTML.dll>
	using namespace EXHTMLLib;
*/
EXHTMLLib::IHTMLPtr spHTML1 = GetDlgItem(IDC_HTML1)->GetControlUnknown();
spHTML1->PutText(L"first line<br>second line<br>third line");
spHTML1->PutSelStart(spHTML1->GetXYToPosition(0,1));
spHTML1->PutSelLength(11);
spHTML1->PutHideSelection(VARIANT_FALSE);
spHTML1->PutFormatSelection(EXHTMLLib::exHTMLFormatBold,VARIANT_TRUE);
spHTML1->PutFormatSelection(EXHTMLLib::exHTMLFormatAlign,long(1));
OutputDebugStringW( _bstr_t(spHTML1->GetFormatSelection(EXHTMLLib::exHTMLFormatBold)) );
spHTML1->PutSelStart(spHTML1->GetXYToPosition(0,2));
spHTML1->PutSelLength(-1);
spHTML1->PutFormatSelection(EXHTMLLib::exHTMLFormatUnderline,VARIANT_TRUE);
spHTML1->PutFormatSelection(EXHTMLLib::exHTMLFormatAlign,long(2));

C++ Builder

HTML1->Text = L"first line<br>second line<br>third line";
HTML1->SelStart = HTML1->XYToPosition[0,1];
HTML1->SelLength = 11;
HTML1->HideSelection = false;
HTML1->FormatSelection[Exhtmllib_tlb::HTMLFormatEnum::exHTMLFormatBold] = TVariant(true);
HTML1->FormatSelection[Exhtmllib_tlb::HTMLFormatEnum::exHTMLFormatAlign] = TVariant(1);
OutputDebugString( PChar(HTML1->FormatSelection[Exhtmllib_tlb::HTMLFormatEnum::exHTMLFormatBold]) );
HTML1->SelStart = HTML1->XYToPosition[0,2];
HTML1->SelLength = -1;
HTML1->FormatSelection[Exhtmllib_tlb::HTMLFormatEnum::exHTMLFormatUnderline] = TVariant(true);
HTML1->FormatSelection[Exhtmllib_tlb::HTMLFormatEnum::exHTMLFormatAlign] = TVariant(2);

C#

exhtml1.Text = "first line<br>second line<br>third line";
exhtml1.SelStart = exhtml1.get_XYToPosition(0,1);
exhtml1.SelLength = 11;
exhtml1.HideSelection = false;
exhtml1.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold,true);
exhtml1.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,1);
System.Diagnostics.Debug.Print( exhtml1.get_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold).ToString() );
exhtml1.SelStart = exhtml1.get_XYToPosition(0,2);
exhtml1.SelLength = -1;
exhtml1.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatUnderline,true);
exhtml1.set_FormatSelection(exontrol.EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,2);

JScript/JavaScript

<BODY onload="Init()">
<OBJECT CLASSID="clsid:0036F83C-D892-4B7B-AA0B-BEDD8D16A738" id="HTML1"></OBJECT>

<SCRIPT LANGUAGE="JScript">
function Init()
{
	HTML1.Text = "first line<br>second line<br>third line";
	HTML1.SelStart = HTML1.XYToPosition(0,1);
	HTML1.SelLength = 11;
	HTML1.HideSelection = false;
	HTML1.FormatSelection(1) = true;
	HTML1.FormatSelection(8) = 1;
	alert( HTML1.FormatSelection(1) );
	HTML1.SelStart = HTML1.XYToPosition(0,2);
	HTML1.SelLength = -1;
	HTML1.FormatSelection(4) = true;
	HTML1.FormatSelection(8) = 2;
}
</SCRIPT>
</BODY>

VBScript

<BODY onload="Init()">
<OBJECT CLASSID="clsid:0036F83C-D892-4B7B-AA0B-BEDD8D16A738" id="HTML1"></OBJECT>

<SCRIPT LANGUAGE="VBScript">
Function Init()
	With HTML1
		.Text = "first line<br>second line<br>third line"
		.SelStart = .XYToPosition(0,1)
		.SelLength = 11
		.HideSelection = False
		.FormatSelection(1) = True
		.FormatSelection(8) = 1
		alert( .FormatSelection(1) )
		.SelStart = .XYToPosition(0,2)
		.SelLength = -1
		.FormatSelection(4) = True
		.FormatSelection(8) = 2
	End With
End Function
</SCRIPT>
</BODY>

C# for /COM

axHTML1.Text = "first line<br>second line<br>third line";
axHTML1.SelStart = axHTML1.get_XYToPosition(0,1);
axHTML1.SelLength = 11;
axHTML1.HideSelection = false;
axHTML1.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold,true);
axHTML1.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,1);
System.Diagnostics.Debug.Print( axHTML1.get_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold).ToString() );
axHTML1.SelStart = axHTML1.get_XYToPosition(0,2);
axHTML1.SelLength = -1;
axHTML1.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatUnderline,true);
axHTML1.set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,2);

X++ (Dynamics Ax 2009)

public void init()
{
	;

	super();

	exhtml1.Text("first line<br>second line<br>third line");
	exhtml1.SelStart(exhtml1.XYToPosition(0,1));
	exhtml1.SelLength(11);
	exhtml1.HideSelection(false);
	exhtml1.FormatSelection(1/*exHTMLFormatBold*/,COMVariant::createFromBoolean(true));
	exhtml1.FormatSelection(8/*exHTMLFormatAlign*/,COMVariant::createFromInt(1));
	print( exhtml1.FormatSelection(1/*exHTMLFormatBold*/) );
	exhtml1.SelStart(exhtml1.XYToPosition(0,2));
	exhtml1.SelLength(-1);
	exhtml1.FormatSelection(4/*exHTMLFormatUnderline*/,COMVariant::createFromBoolean(true));
	exhtml1.FormatSelection(8/*exHTMLFormatAlign*/,COMVariant::createFromInt(2));
}

Delphi 8 (.NET only)

with AxHTML1 do
begin
	Text := 'first line<br>second line<br>third line';
	SelStart := get_XYToPosition(0,1);
	SelLength := 11;
	HideSelection := False;
	set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold,TObject(True));
	set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,TObject(1));
	OutputDebugString( get_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatBold) );
	SelStart := get_XYToPosition(0,2);
	SelLength := -1;
	set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatUnderline,TObject(True));
	set_FormatSelection(EXHTMLLib.HTMLFormatEnum.exHTMLFormatAlign,TObject(2));
end

Delphi (standard)

with HTML1 do
begin
	Text := 'first line<br>second line<br>third line';
	SelStart := XYToPosition[0,1];
	SelLength := 11;
	HideSelection := False;
	FormatSelection[EXHTMLLib_TLB.exHTMLFormatBold] := OleVariant(True);
	FormatSelection[EXHTMLLib_TLB.exHTMLFormatAlign] := OleVariant(1);
	OutputDebugString( FormatSelection[EXHTMLLib_TLB.exHTMLFormatBold] );
	SelStart := XYToPosition[0,2];
	SelLength := -1;
	FormatSelection[EXHTMLLib_TLB.exHTMLFormatUnderline] := OleVariant(True);
	FormatSelection[EXHTMLLib_TLB.exHTMLFormatAlign] := OleVariant(2);
end

VFP

with thisform.HTML1
	.Text = "first line<br>second line<br>third line"
	.SelStart = .XYToPosition(0,1)
	.SelLength = 11
	.HideSelection = .F.
	.Object.FormatSelection(1) = .T.
	.Object.FormatSelection(8) = 1
	DEBUGOUT( .FormatSelection(1) )
	.SelStart = .XYToPosition(0,2)
	.SelLength = -1
	.Object.FormatSelection(4) = .T.
	.Object.FormatSelection(8) = 2
endwith

dBASE Plus

local oHTML

oHTML = form.EXHTMLACTIVEXCONTROL1.nativeObject
oHTML.Text = "first line<br>second line<br>third line"
oHTML.SelStart = oHTML.XYToPosition(0,1)
oHTML.SelLength = 11
oHTML.HideSelection = false
oHTML.Template = [FormatSelection(1) = True] // oHTML.FormatSelection(1) = true
oHTML.Template = [FormatSelection(8) = 1] // oHTML.FormatSelection(8) = 1
? Str(oHTML.FormatSelection(1)) 
oHTML.SelStart = oHTML.XYToPosition(0,2)
oHTML.SelLength = -1
oHTML.Template = [FormatSelection(4) = True] // oHTML.FormatSelection(4) = true
oHTML.Template = [FormatSelection(8) = 2] // oHTML.FormatSelection(8) = 2

XBasic (Alpha Five)

Dim oHTML as P

oHTML = topparent:CONTROL_ACTIVEX1.activex
oHTML.Text = "first line<br>second line<br>third line"
oHTML.SelStart = oHTML.XYToPosition(0,1)
oHTML.SelLength = 11
oHTML.HideSelection = .f.
oHTML.Template = "FormatSelection(1) = True" // oHTML.FormatSelection(1) = .t.
oHTML.Template = "FormatSelection(8) = 1" // oHTML.FormatSelection(8) = 1
? oHTML.FormatSelection(1) 
oHTML.SelStart = oHTML.XYToPosition(0,2)
oHTML.SelLength = -1
oHTML.Template = "FormatSelection(4) = True" // oHTML.FormatSelection(4) = .t.
oHTML.Template = "FormatSelection(8) = 2" // oHTML.FormatSelection(8) = 2

Visual Objects


oDCOCX_Exontrol1:Text := "first line<br>second line<br>third line"
oDCOCX_Exontrol1:SelStart := oDCOCX_Exontrol1:[XYToPosition,0,1]
oDCOCX_Exontrol1:SelLength := 11
oDCOCX_Exontrol1:HideSelection := false
oDCOCX_Exontrol1:[FormatSelection,exHTMLFormatBold] := true
oDCOCX_Exontrol1:[FormatSelection,exHTMLFormatAlign] := 1
OutputDebugString(String2Psz( AsString(oDCOCX_Exontrol1:[FormatSelection,exHTMLFormatBold]) ))
oDCOCX_Exontrol1:SelStart := oDCOCX_Exontrol1:[XYToPosition,0,2]
oDCOCX_Exontrol1:SelLength := -1
oDCOCX_Exontrol1:[FormatSelection,exHTMLFormatUnderline] := true
oDCOCX_Exontrol1:[FormatSelection,exHTMLFormatAlign] := 2

PowerBuilder

OleObject oHTML

oHTML = ole_1.Object
oHTML.Text = "first line<br>second line<br>third line"
oHTML.SelStart = oHTML.XYToPosition(0,1)
oHTML.SelLength = 11
oHTML.HideSelection = false
oHTML.FormatSelection(1,true)
oHTML.FormatSelection(8,1)
MessageBox("Information",string( String(oHTML.FormatSelection(1)) ))
oHTML.SelStart = oHTML.XYToPosition(0,2)
oHTML.SelLength = -1
oHTML.FormatSelection(4,true)
oHTML.FormatSelection(8,2)

Visual DataFlex

Procedure OnCreate
	Forward Send OnCreate
	Set ComText to "first line<br>second line<br>third line"
	Set ComSelStart to (ComXYToPosition(Self,0,1))
	Set ComSelLength to 11
	Set ComHideSelection to False
	Set ComFormatSelection OLEexHTMLFormatBold to True
	Set ComFormatSelection OLEexHTMLFormatAlign to 1
	Showln (ComFormatSelection(Self,OLEexHTMLFormatBold))
	Set ComSelStart to (ComXYToPosition(Self,0,2))
	Set ComSelLength to -1
	Set ComFormatSelection OLEexHTMLFormatUnderline to True
	Set ComFormatSelection OLEexHTMLFormatAlign to 2
End_Procedure

XBase++

#include "AppEvent.ch"
#include "ActiveX.ch"

PROCEDURE Main
 	LOCAL oForm
	LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL
	LOCAL oHTML

	oForm := XbpDialog():new( AppDesktop() )
	oForm:drawingArea:clipChildren := .T.
	oForm:create( ,,{100,100}, {640,480},, .F. )
	oForm:close  := {|| PostAppEvent( xbeP_Quit )}

	oHTML := XbpActiveXControl():new( oForm:drawingArea )
	oHTML:CLSID  := "Exontrol.HTML.1" /*{0036F83C-D892-4B7B-AA0B-BEDD8D16A738}*/
	oHTML:create(,, {10,60},{610,370} )

		oHTML:Text := "first line<br>second line<br>third line"
		oHTML:SelStart := oHTML:XYToPosition(0,1)
		oHTML:SelLength := 11
		oHTML:HideSelection := .F.
		oHTML:SetProperty("FormatSelection",1/*exHTMLFormatBold*/,.T.)
		oHTML:SetProperty("FormatSelection",8/*exHTMLFormatAlign*/,1)
		DevOut( Transform(oHTML:FormatSelection(1/*exHTMLFormatBold*/),"") )
		oHTML:SelStart := oHTML:XYToPosition(0,2)
		oHTML:SelLength := -1
		oHTML:SetProperty("FormatSelection",4/*exHTMLFormatUnderline*/,.T.)
		oHTML:SetProperty("FormatSelection",8/*exHTMLFormatAlign*/,2)

	oForm:Show()
	DO WHILE nEvent != xbeP_Quit
		nEvent := AppEvent( @mp1, @mp2, @oXbp )
		oXbp:handleEvent( nEvent, mp1, mp2 )
	ENDDO 
RETURN