#206731 - 2013-02-19 02:10 PM
RichTextBox.html not working correctly?
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
I'm currently working on a small script that uses Kixforms to present the gui. I use a RichtTextBox object to be able to do some formatting of the text (bold, line breaks).
I am able to load html code into the object via RichTextBox.html, but when I add some additional text, RichTextBox.html doesn't return the actual content of the RichtTextBox, but RichTextBox.text shows the correct text. Is this an error or am I missing something?
Break On
Dim $Ret, $System, $TestForm, $cmd
$Ret = SetOption("explicit", "on")
$TestForm = CreateObject("Kixtart.Form")
If @ERROR
$cmd = 'msiexec /i "' + @SCRIPTDIR + '\KiXforms.msi" /qb /norestart'
Shell $Cmd
EndIf
$System = CreateObject("KiXtart.System")
Dim $Form1
$Form1 = $System.Form()
$Form1.Text = "Test"
Dim $RichTextBox1
$RichTextBox1 = $Form1.Controls.RichTextBox()
$RichTextBox1.Location = 13, 13
$RichTextBox1.Size = 259, 195
Dim $Button1
$Button1 = $Form1.Controls.Button()
$Button1.Text = "Done"
$Button1.Size = 75, 23
$Button1.Location = 96, 227
$Button1.OnClick = "onDone($$Form1, $$RichTextBox1)"
$RichTextBox1.html = "This is an example test. <Br><Br><Br>Text you add here is not shown via .html, but via .text, try it!<p> An example of <b>BoldText</b></p>"
Dim $Null
$Form1.Show
While $Form1.Visible
$Null=Execute($System.Application.DoEvents)
Loop
Function onDone($Form1, $RichTextBox1)
Dim $Ret
$Ret = MessageBox($RichTextBox1.html, "HTML code is", 16)
$Ret = MessageBox($RichTextBox1.text, "Text code is", 16)
$Form1.visible = false
EndFunction
|
Top
|
|
|
|
#206739 - 2013-02-20 08:21 AM
Re: RichTextBox.html not working correctly?
[Re: ShaneEP]
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
Hi Shane,
the idea behind my script is to enable a user to select some template text from a list and then add some specific details. The template text is read from a ini file. To not loose the formatting, it would be nice to get the content of the rich text box with the .html property to later use it in the body of a mail message.
|
Top
|
|
|
|
#206755 - 2013-02-22 03:19 PM
Re: RichTextBox.html not working correctly?
[Re: ShaneEP]
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
Thanks Shane for your feedback, I fully agree with your outcome, I'll implement it differently.
|
Top
|
|
|
|
#206771 - 2013-02-23 08:17 PM
Re: RichTextBox.html not working correctly?
[Re: Lonkero]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Here is a rough work around that might work for you...IF the machines that run the forms have MS Word installed. It essentially saves the edited richtextbox text to a rtf, then uses Word in the background to convert it to html.
Break On
Dim $Ret, $System, $TestForm, $cmd
$Ret = SetOption("explicit", "on")
$TestForm = CreateObject("Kixtart.Form")
If @ERROR
$cmd = 'msiexec /i "' + @SCRIPTDIR + '\KiXforms.msi" /qb /norestart'
Shell $Cmd
EndIf
$System = CreateObject("KiXtart.System")
Dim $Form1
$Form1 = $System.Form()
$Form1.Text = "Test"
Dim $RichTextBox1
$RichTextBox1 = $Form1.Controls.RichTextBox()
$RichTextBox1.Location = 13, 13
$RichTextBox1.Size = 259, 195
Dim $Button1
$Button1 = $Form1.Controls.Button()
$Button1.Text = "Done"
$Button1.Size = 75, 23
$Button1.Location = 96, 227
$Button1.OnClick = "onDone($$Form1, $$RichTextBox1)"
$RichTextBox1.html = "This is an example test. <Br><Br><Br>Text you add here is not shown via .html, but via .text, try it!<p> An example of <b>BoldText</b></p>"
Dim $Null
$Form1.Show
While $Form1.Visible
$Null=Execute($System.Application.DoEvents)
Loop
Function onDone($Form1,$RichTextBox)
Dim $html,$nul
$html = RTFBoxHTML($RichTextBox)
$nul = MessageBox($html,"HTML",0)
$Form1.visible = 0
EndFunction
Function RTFBoxHTML($RichTextBox)
Dim $rtffile,$htmlfile,$nul,$word,$doc,$fso
$rtffile = "%temp%\"+@Ticks+".rtf"
$htmlfile = "%temp%\"+@Ticks+".html"
$nul = Execute('$$RichTextBox.SaveFile($$rtffile)')
$word = CreateObject("Word.Application")
$doc = $word.Documents.Open($rtffile)
$doc = $word.ActiveDocument()
$doc.SaveAs($htmlfile, 10)
$doc.Close()
$word.Quit()
$fso = CreateObject("Scripting.FileSystemObject").GetFile($htmlfile)
$RTFBoxHTML = $fso.OpenAsTextStream(1,-2).Read($fso.size)
Del $rtffile
del $htmlfile
EndFunction
|
Top
|
|
|
|
#206788 - 2013-02-25 10:24 AM
Re: RichTextBox.html not working correctly?
[Re: ShaneEP]
|
Sam_B
Getting the hang of it
Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
|
This sounds interesting, thanks Shane, I'll try this!
|
Top
|
|
|
|
#206789 - 2013-02-25 11:04 AM
Re: RichTextBox.html not working correctly?
[Re: Sam_B]
|
It_took_my_meds
Hey THIS is FUN
   
Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
|
I can vouch for the EasyByte RTF to HTML COM object. It's not free but it works really well.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 323 anonymous users online.
|
|
|