Page 1 of 1 1
Topic Options
#202133 - 2011-05-06 08:18 PM Kixforms RichTextBox
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2101
Loc: Tulsa, OK
Does anyone have any experience with the richtextbox control in kixforms? I'm trying to use it to generate a formatted report type document. Not sure how to set the formatting of the text line by line, or if it's even possible.
Top
#202134 - 2011-05-06 09:33 PM Re: Kixforms RichTextBox [Re: ShaneEP]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Classic or .net ?
_________________________



Top
#202135 - 2011-05-06 09:41 PM Re: Kixforms RichTextBox [Re: Jochen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2101
Loc: Tulsa, OK
Classic. I found that you can use HTML in the richtextbox which would work...except that it doesnt recognize < pre > tags or & nbsp so it's becoming difficult to get columns to line up lol.
Top
#202136 - 2011-05-06 09:46 PM Re: Kixforms RichTextBox [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2101
Loc: Tulsa, OK
Also tried the < table > route but its not recognized either.
Top
#202137 - 2011-05-07 12:48 AM Re: Kixforms RichTextBox [Re: ShaneEP]
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
You can do it. You just need to select the text you want with .SelectionStart and .SelectionLength. Then you can format the selection with properties such as .SelectionFontUnderline, .SelectionFontBold, etc, or even .SelectedText.

Here's some example code that adjusts a RichTextBox so that pasted HTML or a typed URL is formatted correctly. (I use this as part of an email body editor that allows people to create scheduled mail merges with information from a database. It is triggered by the OnKeyDown event or pressing a paste button.)

 Code:
Function FixURL(Optional $txtBody)

	; This regex fixes pasted URL's so they are converted back to the way they are displayed in HTML
	; Richard.von.Mallesch@csiro.au <mailto:Richard.von.Mallesch@csiro.au>  -> Richard.von.Mallesch@csiro.au
	; www.csiro.au <http://www.csiro.au/>  -> www.csiro.au
	; https://www.csiro.au:443/foo/bar.htm <https://www.csiro.au:443/foo/bar.htm>  -> https://www.csiro.au:443/foo/bar.htm
	; <\\server1-syd\share$\file.text>  -> \\server1-syd\share$\file.text
	; It also checks for URLS and formats them as such.

	Dim $KeyCode, $Paste, $regEx, $regEx2, $ss, $match, $diff, $text, $matched

	If VarType($txtBody)
		$Paste = 1
	Else
		$txtBody = $System.Sender
		$KeyCode = $txtBody.KeyCode
	EndIf

	$ss = $txtBody.SelectionStart
	$text = Replace($txtBody.Text, @CRLF, Chr(10))
	If Len($text) = $ss
		$text = $text + " "
	Else
		$text = Left($text, $ss + 1)
	EndIf
	If $KeyCode = 32 Or $KeyCode = 13 Or ($KeyCode = 86 And $txtBody.LastKey = 17) Or $Paste ;Space, Enter, Ctrl+V, or pasted
		$regEx = CreateObject("VBscript.RegExp")
		$regEx.Pattern = "<?((\\\\[\w-.\\$]+)|((([\w.%+-]+@)|(\w{3,6}:(//)?)|(\w+\.))\w+(\.\w+)+(:\d+)?[^\s>]*))>?( <\w{0,6}:?(//)?\1/?>)?"
		$regEx.Global = 1
		$regEx2 = CreateObject("VBscript.RegExp")
		$regEx2.Pattern = "^\w+(\.\w+){2,}$"
		If $KeyCode = 32 Or $KeyCode = 13 $txtBody.LastSelectionStart = InStrRev(Replace(Left($text, -2), Chr(10), " "), " ") EndIf
		For Each $match in $regEx.Execute(SubStr($text, $txtBody.LastSelectionStart + 1, $ss - $txtBody.LastSelectionStart))
			If Not ($match.Value = $match.SubMatches(0) And $RegEx2.Test($match.Value))
				$txtBody.SelectionStart = $txtBody.LastSelectionStart + $match.FirstIndex + $diff
				$txtBody.SelectionLength = $match.Length
				$txtBody.SelectionColor = "Blue"
				$txtBody.SelectionFontUnderline = 1
				$txtBody.SelectedText = $match.SubMatches(0)
				$diff = $diff + Len($match.SubMatches(0)) - $match.Length
			EndIf
			$matched = 1
		Next
		If $matched And $ss + $diff = $txtBody.SelectionStart + $txtBody.SelectionLength
			$txtBody.SelectionStart = $ss + $diff
			$txtBody.SelectionColor = $txtBody.LastColour
			$txtBody.SelectionFontUnderLine = 0
			$txtBody.SelectedText = $txtBody.SelectedText + " "
			$txtBody.SelectionStart = $ss + $diff + 1
		Else
			$txtBody.SelectionStart = $ss + $diff
		EndIf
	Else
		If Right($text, 1) = " " And $KeyCode = 8 ; BackSpace
			$regEx = CreateObject("VBScript.RegExp")
			$regEx.Pattern = "((\\\\[\w-.\\$]+)|((([\w.%+-]+@)|(\w{3,6}:(//)?)|(\w+\.))\w+(\.\w+)+(:\d+)?[^\s>]*))"
			If $regEx.Test($txtBody.LastWord) And $txtBody.SelectionFontUnderLine = 1
				$txtBody.SelectionStart = $txtBody.LastSelectionStart - Len($txtBody.LastWord)
				$txtBody.SelectionLength = Len($txtBody.LastWord) - 1
				$txtBody.SelectedText = $txtBody.LastWord
				$txtBody.SelectionColor = $txtBody.LastColour
				$txtBody.SelectionStart = $txtBody.LastSelectionStart
				$text = $text + " "
			EndIf
		Else
			$txtBody.LastKey = $KeyCode
			$txtBody.LastColour = $txtBody.SelectionColor
		EndIf
	EndIf
	$text = Left($text, -1)
	$ = InStrRev(Replace($text, Chr(10), " "), " ")
	$txtBody.LastWord = SubStr($text, IIf($, $, 1))
	$txtBody.LastSelectionStart = $txtBody.SelectionStart

EndFunction

If you can't get what you want that way, you could also generate the RichText code and set .rtf to it.

Cheers,

Richard

Top
#202138 - 2011-05-07 08:21 AM Re: Kixforms RichTextBox [Re: ShaneEP]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hmm .. I was quite sure that I did used .RichTextBox() in one of my older apps like PostPrep .. but the Preview was inside an ie Form..

Then I thought I had one in another project of mine .. but that was 'only' a .GridView()..

So, nope, no experience with RichTextBoxes \:\(
_________________________



Top
#202142 - 2011-05-07 04:46 PM Re: Kixforms RichTextBox [Re: Jochen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2101
Loc: Tulsa, OK
I think I've decided on how I'm going to go about it. It's a little overkill probably. But I'm gonna generate the text in the Richtextbox using the normal rtf formatting, but in the background I'm gonna write my own HTML file with the same info. This way it's easier to display the info in nicely formatted rows/columns in the rtb...and then I can still use the IE.application to print the .html file in the background when they want to print the report. I was having problems getting IE to print .rtf files silently.
Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 241 anonymous users online.
Newest Members
Thechadpma, CestMoi, MeMyselfAndI, Praveer, Ollero
17745 Registered Users

Generated in 0.032 seconds in which 0.011 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org