I’m pretty new to styled text, but was just starting to play around with it.
It is possible to paste highlighted text into a text area, but I don’t know how to do this via code.
One hackish way to do it is with Word, but this is not a good solution for obvious reasons.
dim w as new WordApplication
dim d as WordDocument = w.Documents.Add
d.Activate
dim s as WordSelection
s = w.Selection
s.TypeText "This is a Test."
s.WholeStory
S.Range.HighlightColorIndex = 7
s.Copy
TextArea1.Paste
w.DisplayAlerts = false
w.Quit
Anyone have some ideas, before I report this to Xojo as a feature request?
Are you asking how to insert text into a Styled Text area, then apply the styling of your choice to it?
If so… very simple.
Look at
SELSTART
SELLENGTH
SELBOLD
etc.
and also STYLERUNS
here is an example for the registration screen of one of my apps
Dim days As Integer=DaysRemaining
Me.selstart=0
Me.SelLength=0
Me.SelBold=True
Me.SelUnderline=True
Me.SelTextColor=&cf0f0f0
Me.seltext="Register "+pgm_name+" now."+EndOfLine
Me.SelBold=False
Me.SelUnderline=False
Me.SelTextColor=&cf0f0f0
If days>0 Then
Me.seltext= _
EndOfLine+ _
"This is an evaluation version of '"+pgm_name+"', and has no restrictions over the full version. " + _
"However the evaluation period expires in "+Str(days)+" days. "+ _
" Otherwise it is 100% functional."+EndOfLine+EndOfLine+_
"To purchase the Full version and unlock all the functionality, just click the "
//
Else
Me.seltext= _
EndOfLine+ _
"This evaluation version of '"+pgm_name+"', and has expired. " +EndOfLine + _
"If you wish to continue to use "+pgm_name+" you must purchase a license key, just click the "
pbDEMO.Enabled=False
End If
Me.SelBold=True
Me.SelTextColor=&c00ee00
Me.seltext="'Buy Now'"
//
Me.SelBold=False
Me.SelTextColor=&cf0f0f0
Me.seltext=" button below, or enter an existing registration passcode for "
//
Me.SelBold=True
Me.SelTextColor=&ceeee00
Me.seltext="Serial #"+Registered_Serial
Me.SelBold=False
Me.SelTextColor=&cf0f0f0
Me.seltext=" and press "
Me.SelBold=True
Me.SelTextColor=&c00ee00
Me.seltext="'OK'"
StyleText area does not support “highlight” background colors… the only way is to emulate the entire area using a canvas (there are two 3rd party controls that come to mind CEF and FTC)…
By “not support” i assume that you mean text background can’t be set using a stylerun.
It seems like highlighted text is fundamentally supported in the text area because you can either paste highlight text or add it from RTF and it displays correctly. I’m trying the MBS RTF functions, but would be interested in checking out the controls you mentioned. Any links?
I just tried this…
I created a document in Word… set some characters to RED, and others to GREEN background.
when pasted into a TextArea… ONLY THE RED appeared… the GREEN background was removed…
leading me to believe TextArea highlighted text is not “fundamentally supported”