Rich Text Box Tricks and Tips - VBForums
-
Upload
saravana-kumar -
Category
Documents
-
view
354 -
download
1
Transcript of Rich Text Box Tricks and Tips - VBForums
Visual Basic Code from FreeVBCode
Get and Set Word file Attributes with VB.NET
Calculate Age in Visual Basic 2005, Counting Leap years
Spatial Matrix Memory Game
Introduction to Cryptoanalysis
Linked List implementation in Visual Basic
Submit your code to FreeVBCode
VBForums > VBForums CodeBank > CodeBank - Visual Basic 6 and earlier
RichTextBox Tricks and TipsUser Name User Name Remember Me?
Password Log in
Register FAQ Calendar Today's Posts VB Jobs Search
Page 1 of 4 1 2 3 4 >
Thread Tools Display Modes
Aug 19th, 2005, 10:41
AM #1
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
RichTextBox Tricks and Tips
The following posts contain a few things that you can do with RichTextBoxes that you might not have
known that you could do. If any of you know of other non-standard things that can be done with
RichTextBoxes, feel free to add to this list.
Highlight text
SuperScript and SubScript
Insert tables
Insert Pictures
Find and Replace Common Dialog
Spell Checking class
Get Cursor Line and Column Position
Detect and respond to hyperlinks
WYSIWYG printing (msdn)
Insert Hyperlinked text
Add animated GIF's to your RichTextBox
Last edited by moeur; Mar 4th, 2008 at 10:12 AM.
Aug 19th,
2005, 10:43 AM #2
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Highlighting text
Since there is no .SelHighlight property of the RichTextBox control, I created one.Code:
To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE. To participate in the message forums BELOW, click here
IT Professionals Solutions eBook Library Webopedia Login RegisterDevelopers
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 1/17
Public Sub HighLight(RTB As RichTextBox, lColor As Long)
'add new color to color table
'add tags \highlight# and \highlight0
'where # is new color number
Dim iPos As Long
Dim strRTF As String
Dim bkColor As Integer
With RTB
iPos = .SelStart
'bracket selection
.SelText = Chr(&H9D) & .SelText & Chr(&H81)
strRTF = RTB.TextRTF
'add new color
bkColor = AddColorToTable(strRTF, lColor)
'add highlighting
strRTF = Replace(strRTF, "\'9d", "\up1\highlight" & CStr(bkColor) & "")
strRTF = Replace(strRTF, "\'81", "\highlight0\up0 ")
.TextRTF = strRTF
.SelStart = iPos
End With
End Sub
Notice that in addition to inserting the \highlight tags I also insert \up# tags.
This is so that I can check to see if a selection is highlighted by querying the
.SelCharOffset function. This routine relies on the following function that adds
a new color to the RTF color tableCode:
Function AddColorToTable(strRTF As String, lColor As Long) As Integer
Dim iPos As Long, jpos As Long
Dim ctbl As String
Dim tagColors
Dim nColors As Integer
Dim tagNew As String
Dim i As Integer
Dim iLen As Integer
Dim split1 As String
Dim split2 As String
'make new color into tag
tagNew = "\red" & CStr(lColor And &HFF) & _
"\green" & CStr(Int(lColor / &H100) And &HFF) & _
"\blue" & CStr(Int(lColor / &H10000))
'find colortable
iPos = InStr(strRTF, "{\colortbl")
If iPos > 0 Then 'if table already exists
jpos = InStr(iPos, strRTF, ";}")
'color table
ctbl = Mid(strRTF, iPos + 12, jpos - iPos - 12)
'array of color tags
tagColors = Split(ctbl, ";")
nColors = UBound(tagColors) + 2
'see if our color already exists in table
For i = 0 To UBound(tagColors)
If tagColors(i) = tagNew Then
AddColorToTable = i + 1
Exit Function
Last edited by moeur; Mar 12th, 2007 at 07:54 PM.
Aug 19th,
2005, 10:45 AM #3
moeurOld Member
Super and Subscripting
Two other functions that the RichTextBox control does not gives us are super and subscripting.
As before we can accomplish this by inserting RTF code. Notice again that I also add \up0
and \dn0 tags so that I can determine if text has been subscripted by querying the
.SelCharOffset property.
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 2/17
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Code:
Public Sub SetSubScript(RTB As RichTextBox)
Dim iPos As Long
Dim strRTF As String
With RTB
If .SelCharOffset >= 0 Then
'subscript the current selection
iPos = .SelStart
.SelText = Chr(&H9D) & .SelText & Chr(&H81)
strRTF = Replace(.TextRTF, "\'9d", "\sub\dn2 ")
.TextRTF = Replace(strRTF, "\'81", "\nosupersub\up0 ")
.SelStart = iPos
Else 'turn off subscripting
.SelText = Chr(&H9D) & .SelText
strRTF = .TextRTF
.TextRTF = Replace(strRTF, "\'9d", "\nosupersub\up0 ", , 1)
End If
End With
End Sub
Public Sub SetSuperScript(RTB As RichTextBox)
'add tags \super\up1 and \nosupersub\up0
Dim iPos As Long
Dim strRTF As String
With RTB
iPos = .SelStart
If RTB.SelCharOffset <= 0 Then
'superscript the current selection
.SelText = Chr(&H9D) & .SelText & Chr(&H80)
strRTF = Replace(.TextRTF, "\'9d", "\super\up2 ")
.TextRTF = Replace(strRTF, "\'81", "\nosupersub\up0 ")
Else 'turn off
.SelText = Chr(&H9D) & .SelText
Last edited by moeur; Mar 12th, 2007 at 07:57 PM.
Aug 19th,
2005, 10:47 AM #4
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Insert Tables
Another useful functionality that can be added to the RichTextBox controls is the ability to insert tables.
The RichTextBox controls support a limited subset of the table related Rich Text Format tags, but none
of that is made accessible to users of the control. I've attached a class that you can use to insert tables
into your RichTextBox controls.
Properties - all sizes are in twips
xLeft - Position of the left edge of the table
isCentered - Set to True to center the table
Rows - Sets or returns the number of rows in the table
Columns - Sets or returns the number of columns in the table
Row - An Array of Rows (1 to Rows)
Column - An Array of columns (1 to Columns)
Column(i).xWidth - Width of the ith column
Cell - A 2-d Array of Cells (1 to Rows, 1 to Columns)
Cell(r, c).Contents - Sets or returns the contents of the cell
Methods
InsertTable(RTB As RichTextBox) - Inserts the table into the RichTextBox at the currrent cursor position.
An example of use isCode:
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 3/17
Option Explicit
Dim RTFtable As clsRTFtable
Private Declare Function LockWindowUpdate Lib "user32" ( _
ByVal hwndLock As Long _
) As Long
Private Sub Command1_Click()
Dim i As Integer
Set RTFtable = New clsRTFtable
'stop flicker
Call LockWindowUpdate(RichTextBox1.hWnd)
For i = 1 To 5
With RTFtable
'set the size of the table
.Columns = 3
.Rows = 2
'fill the cells
'Row 1
.Cell(1, 1).Contents = "Row 1"
.Cell(1, 2).Contents = "Column2"
.Cell(1, 3).Contents = "Column3"
'Row 2
.Cell(2, 1).Contents = "Row2"
.Cell(2, 2).Contents = "R2C2"
.Cell(2, 3).Contents = "R2C3"
'do we want to center it on the page?
.isCentered = True
'insert the table at the current cursor postion
Attached Files
RTFtable.zip (5.3 KB, 7028 views)
Last edited by moeur; Mar 12th, 2007 at 08:10 PM.
Aug 19th,
2005, 10:50 AM #5
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Insert Pictures
There are several ways to insert pictures into a RichTextBox control.
This is one method that does not rely on the clipboard, but does use some
metafile stuff. Here is the routine to insert the pictureCode:
'Inserts the picture at the current insertion point
Public Function InsertPicture(RTB As RichTextBox, pic As StdPicture)
Dim strRTFall As String
Dim lStart As Long
With RTB
.SelText = Chr(&H9D) & .SelText & Chr(&H81)
strRTFall = .TextRTF
strRTFall = Replace(strRTFall, "\'9d", PictureToRTF(pic))
.TextRTF = strRTFall
'position cursor past new insertion
lStart = .Find(Chr(&H81))
strRTFall = Replace(strRTFall, "\'81", "")
.TextRTF = strRTFall
.SelStart = lStart
End With
End Function
Here is the routine that converts the picture into an RTF stringCode:
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 4/17
'returns the RTF string representation of our picture
Public Function PictureToRTF(pic As StdPicture) As String
Dim hMetaDC As Long, hMeta As Long, hPicDC As Long, hOldBmp As Long
Dim Bmp As BITMAP, Sz As Size, Pt As POINTAPI
Dim sTempFile As String, screenDC As Long
Dim headerStr As String, retStr As String, byteStr As String
Dim ByteArr() As Byte, nBytes As Long
Dim fn As Long, i As Long, j As Long
sTempFile = App.Path & "\~pic" & ((Rnd * 1000000) + 1000000) \ 1 & ".tmp" 'some temprory file
If Dir(sTempFile) <> "" Then Kill sTempFile
'Create a metafile which is a collection of structures that store a
'picture in a device-independent format.
hMetaDC = CreateMetaFile(sTempFile)
'set size of Metafile window
SetMapMode hMetaDC, MM_ANISOTROPIC
SetWindowOrgEx hMetaDC, 0, 0, Pt
GetObject pic.Handle, Len(Bmp), Bmp
SetWindowExtEx hMetaDC, Bmp.Width, Bmp.Height, Sz
'save sate for later retrieval
SaveDC hMetaDC
'get DC compatible to screen
screenDC = GetDC(0)
hPicDC = CreateCompatibleDC(screenDC)
ReleaseDC 0, screenDC
'set out picture as new DC picture
hOldBmp = SelectObject(hPicDC, pic.Handle)
Attached is code plus the declaresAttached Files
modRTFpic.bas (5.9 KB, 2438 views)
Last edited by moeur; Mar 12th, 2007 at 08:19 PM.
Sep 4th,
2005, 05:40 PM #6
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Find and Replace Common Dialog
Until recently I didn't know that you could access the "Find-And-Replace" Common Dialog.
Here is a class that makes it easy to access. The class will work with either a standard TextBox or a
RichTextBox.
Here is an example of how you might use the class.Code:
Option Explicit
'declare with events so that we can override the default
'behavior of the class and/or handle ShowHelp
Dim WithEvents FindDialog As clsFindandReplace
Private Sub Form_Load()
Set FindDialog = New clsFindandReplace
End Sub
Private Sub Command2_Click()
'show the Find and Replace dialog box
'pass the handle of our RichTextBox to
'the class
FindDialog.ShowReplace RTB.hwnd
End Sub
Attached Files
FindAndReplace.zip (16.1 KB, 2419 views)
Last edited by moeur; Mar 12th, 2007 at 08:32 PM.
Sep 5th,
2005, 10:22 PM #7
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 5/17
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Full Featured Spell Checker
Here is a class that provides full spell checking functionality for the RichTextBox. This class has only two
methods:
GetSpellingErrors checks the spelling in all the text of a RTB and returns the number of spelling errors found
and marks then all. A right-click on any error brings up a popup menu with suggested changes. If the user
selects a change from the menu, then the replacement is made.
ClearSpelling clears all the marked errors.
Here is an example of use:Code:
Option Explicit
Private SpellCheck As clsSpellCheck
Private Sub cmdSpellCheck_Click()
SpellCheck.GetSpellingErrors RTB
End Sub
Private Sub cmdStopSpell_Click()
SpellCheck.ClearSpelling
End Sub
Private Sub Form_Load()
Set SpellCheck = New clsSpellCheck
RTB.LoadFile App.Path & "\recipe.rtf"
End Sub
This code also provides an example of several other things.
How to implement the EN_LINK notification function of the RichTextBox. This notification is usually used to
mark hyperlinks and respond to mouse events over them. I use it to mark spelling errors and to bring up a
popup menu of spelling suggestions for the user to select from.
I have included a class that is used to create and respond to popup menus. I put this functionality into a
class because I wanted all the spell checking functionality contained within a class with none of the code
in the form.
Also included is my "Cute Little Subclasser" class. I use this class whenever I want subclassing
capabilities. When this class is declared WithEvents, the user can write code to respond to Windows
messages within the form or class's own module. It also is a little more stable than doing your own
subclassing since it always remembers to turn itself off.
Attached is the source code for all the above mentioned items PLUS a free mispelled recipe!Attached Files
SpellCheck.zip (18.3 KB, 2692 views)
Last edited by moeur; Mar 12th, 2007 at 08:40 PM.
Sep 11th,
2005, 10:58 AM #8
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Get row and column number of cursor
Here is some simple code that will give you the cursor position in a RichTextBox, It gives you the line number and
the column number of the cursor. Attached is a project that demonstrates use of the routine.Code:
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 6/17
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Sub GetCursorPos(RTB As RichTextBox, iLine As Integer, iPos As Integer)
Dim lCount As Long
Dim i As Long
Dim LN As Long
lCount = SendMessage(RTB.hwnd, EM_GETLINECOUNT, 0&, 0&)
LN = SendMessage(RTB.hwnd, EM_LINEINDEX, -1&, 0&)
For i = 1 To lCount
If LN = SendMessage(RTB.hwnd, EM_LINEINDEX, i - 1, 0) Then Exit For
Next i
iLine = i
iPos = RTB.SelStart - LN + 1
End Sub
Attached Files
GetCursorPos.zip (2.5 KB, 2392 views)
Last edited by moeur; Mar 12th, 2007 at 08:42 PM.
Sep 29th,
2005, 11:48 AM #9
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Auto Detect and respond to URLs
The RichTextBox control has the ability to detect URLs as they are typed. It can convert this text into a
hyperlink which can launch a browser when clicked.
To turn on Auto URL detection simply send the RTB an EM_AUTOURLDETECT message.
When the control detects that a URL is being entered, it reformats the text being entered so that it looks like a
hyperlink and marks that text with a CFE_LINK effect.
When the mouse pointer is over text with a CFE_LINK effect, the RTB can be configured to send a message to
its parent. In order to respond to mouse events over the hyperlink text, the parent has to be subclassed or
hooked.
The following code shows how to setup Auto URL detectionCode:
Public Sub EnableAutoURLDetection(RTB As RichTextBox)
'enable auto URL detection
SendMessage RTB.hwnd, EM_AUTOURLDETECT, 1&, ByVal 0&
'subclass the parent of the RTB to receive EN_LINK notifications
Set FormSubClass = New clsSubClass
FormSubClass.Enable RTB.Parent.hwnd
'set RTB to notify parent when user has clicked hyperlink
SendMessage RTB.hwnd, EM_SETEVENTMASK, 0&, ByVal ENM_LINK
End Sub
And to respond to a left mouse click you could do the following in your form's subclass routine.Code:
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 7/17
Private Sub FormSubClass_WMArrival(hwnd As Long, uMsg As Long, wParam As Long, lParam As Long, lRetVal
Dim notifyCode As nmhdr
Dim LinkData As ENLINK
Dim URL As String
Select Case uMsg
Case WM_NOTIFY
CopyMemory notifyCode, ByVal lParam, LenB(notifyCode)
If notifyCode.code = EN_LINK Then
'A RTB sends EN_LINK notifications when it receives certain mouse messages
'while the mouse pointer is over text that has the CFE_LINK effect:
'To receive EN_LINK notifications, specify the ENM_LINK flag in the mask
'sent with the EM_SETEVENTMASK message.
'If you send the EM_AUTOURLDETECT message to enable automatic URL detection,
'the RTB automatically sets the CFE_LINK effect for modified text that it
'identifies as a URL.
CopyMemory LinkData, ByVal lParam, Len(LinkData)
If LinkData.Msg = WM_LBUTTONUP Then
'user clicked on a hyperlink
'get text with CFE_LINK effect that caused message to be sent
URL = Mid(RTB.Text, LinkData.chrg.cpMin + 1, LinkData.chrg.cpMax - LinkData.chrg.cpMin)
'launch the browser here
ShellExecute 0&, "OPEN", URL, vbNullString, "C:\", SW_SHOWNORMAL
End If
End If
lRetVal = FormSubClass.callWindProc(hwnd, uMsg, wParam, lParam)
Attached is a project that demonstrates the whole idea.Attached Files
AutoURLdetect.zip (10.9 KB, 2490 views)
Last edited by moeur; Mar 12th, 2007 at 08:46 PM.
Oct 3rd, 2005, 03:25
PM #10
longwolfFrenzied Member
Join Date: Oct 02Posts: 1,343
Re: RichTextBox Tricks and Tips
Wow, you have some really great stuff here!
But I see one major draw back.
In SpellCheck.zip you have a dll named DBGWPROC.DLL.
Its properties say:
You have a license to use this file only if you have a copy of the book. You may not redistribute this file.
Oct 3rd, 2005, 05:59
PM #11
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
The DbgWProc.Dll is only used for debugging purposes so doesn't really need to be included, but the author (
Matthew Curland) has given his permission to redistribute it. The file is freely available many places around the
iternet.
Last edited by moeur; Oct 6th, 2005 at 12:03 PM.
Jan 16th, 2006, 01:57
PM #12
JustinWNew Member Join Date: Jan 06Posts: 2
Re: RichTextBox Tricks and Tips
Hi:
First off, thanks so much for posting the codes for inserting tables. That's much appreciated!!!
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 8/17
I have access to the control characters for rft documents and what I'd like to do is to have codes that would
allow user to change the boarder of the cell that the user's cursor is in (inside a rich text box).
I have searched the net high and low for info. on how to programatically select all the control characters that is
associated with that cell and then make modification to them (e.g.: flagging \ckbrdk to false).
Could you kindly help me out with this? I would really appreciate it!
Thank you in advance!
Justin
Apr 13th,
2006, 03:17 AM #13
darkiNew Member Join Date: Apr 06Posts: 3
Re: Insert Tables
Hi,
very nice codes...
I found one bug in RTFtable
VB Code:
1. Public Sub InsertTable(RTB As RichTextBox)
2. 'set column widths
3. For c = 1 To mvarColumns
4. strInsert = strInsert & "\cellx"
5. w = mvarxLeft
6. For i = 1 To c
7. [color=Red]w = w + mvarclsColumn(c).xWidth[/color]
8. Next i
9. strInsert = strInsert & CStr(w)
10. Next c
If you have all columns same size you can't see difference, but
must be:
w = w + mvarclsColumn(i).xWidth
Apr 13th, 2006, 09:52
AM #14
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
Thanks darki
May 14th, 2006, 11:24
AM #15
mamacoNew Member Join Date: May 06Posts: 1
Re: RichTextBox Tricks and Tips
Hi All
I have strange problems with the syntax highlighting programming
No.1 Sendmessage is often out of work
'----------------------Quotation----------------------
LN = SendMessage(RTB.hwnd, EM_LINEINDEX, Byval LineNum, 0&)
'----------------------Quotation----------------------
this works fine in ANSI mode(english text),but when I use UNICODE mode,it returns wrong result as always. I have
to seek the preview enter key to locate the fst pos of a line.
No.2
'----------------------Quotation----------------------
.SelStart
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 9/17
.SelLength
.SelColor
'----------------------Quotation----------------------
if selected Line number is under 200,this goes fast,but when it's above 1000,it just stuck over there with a delay
of 1 second or more,within these time,the keyboard action might be all in a mess.
can you give me some suggestion? thx a lot
Jun 2nd, 2006, 09:44
AM #16
BodwadUKKING BODWAD XXI
Join Date: Aug 02Location: NottinghamPosts: 2,164
Re: RichTextBox Tricks and Tips
Maybe I am confused but I am trying to highlight text on the go without changing the cursor position. Is there
anyway to get the RTF text position? Selstart only has it for the standard text and I need the rtf selstart so that
I can insert my own colour tags before and after my word.
Just in case your wondering I am writing a script editor and the cursor jumps the box around whenever I highlight
words
__________________
If you dribble then you are as mad as me
Lost World Creations Website (Astrophotography)
Lene Marlin
Jun 2nd,
2006, 07:24 PM #17
moeurOld Member
Join Date: Nov 04Location: InHiding.... Weather:sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
Probably the easiest thing to do is lock the window while you are doing the highlighting with LockWindowUpdate.
VB Code:
1. Private Declare Function LockWindowUpdate Lib "user32" ( _
2. ByVal hwndLock As Long) As Long
3.
4. Private Sub Command1_Click()
5. Dim iPos As Integer
6. 'save the current cursor position
7. iPos = RTB.SelStart
8. 'prevent the window from changing
9. LockWindowUpdate RTB.hWnd
10. 'highlight a word
11. RTB.Find "is"
12. HighLight RTB, vbYellow
13. 'restore the cursor position
14. RTB.SelStart = iPos
15. 'unlock the window
16. LockWindowUpdate 0
17. End Sub
Jun 5th, 2006, 02:48
AM #18
BodwadUKKING BODWAD XXI
Join Date: Aug 02Location: NottinghamPosts: 2,164
Re: RichTextBox Tricks and Tips
Thanks I shall give it a go
__________________
If you dribble then you are as mad as me
Lost World Creations Website (Astrophotography)
Lene Marlin
Jun 5th, 2006, 02:52
AM #19
BodwadUKKING BODWAD XXI
Re: RichTextBox Tricks and Tips
Thats seems to do it thanks. I had it on the main form hwnd before but changing it to the hwnd of the rich text
box itself seems to do the trick thanks
__________________
If you dribble then you are as mad as me
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 10/17
Join Date: Aug 02Location: NottinghamPosts: 2,164
Lost World Creations Website (Astrophotography)
Lene Marlin
Jun 12th, 2006, 09:47
PM #20
nokmasterFanatic Member Join Date: Nov 02Location: PhilippinesPosts: 877
Re: RichTextBox Tricks and Tips
thanks for that tricks..
but how to autoscroll the richtextbox?
Jun 12th, 2006, 11:50
PM #21
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
what do you mean by autoscroll? What do you want to do?
Jun 13th,
2006, 12:05 AM #22
nokmasterFanatic Member Join Date: Nov 02Location:PhilippinesPosts: 877
Re: RichTextBox Tricks and Tips
@moeur
hi, i mean richtextbox with vertical scroller. if u put this command into command1
VB Code:
1. with rtb
2. .selcolor = vbblack
3. .seltext = "ok" & vbcrlf
4. end with
it will scroll down right? but if you scroll this scroller to up then press the button again it will not scroll.
Jun 13th, 2006, 02:06
AM #23
BodwadUKKING BODWAD XXI
Join Date: Aug 02Location: NottinghamPosts: 2,164
Re: RichTextBox Tricks and Tips
change selstart to the location you want the cursor. It should scroll for you
__________________
If you dribble then you are as mad as me
Lost World Creations Website (Astrophotography)
Lene Marlin
Jun 13th, 2006, 04:29
AM #24
nokmasterFanatic Member Join Date: Nov 02Location: PhilippinesPosts: 877
Re: RichTextBox Tricks and Tips
Quote:
Originally Posted by BodwadUK
change selstart to the location you want the cursor. It should scroll for you
how?
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 11/17
Jun 13th, 2006, 05:01
AM #25
BodwadUKKING BODWAD XXI
Join Date: Aug 02Location: NottinghamPosts: 2,164
Re: RichTextBox Tricks and Tips
you mean it doesnt scroll down until you hit the bottom of the text window with your cursor?
__________________
If you dribble then you are as mad as me
Lost World Creations Website (Astrophotography)
Lene Marlin
Jun 30th, 2006, 06:11
AM #26
Yuji1New Member Join Date: Jun 06Posts: 1
Re: RichTextBox Tricks and Tips
I wish to know how to, uh, well, basically, I am building a chat program for the Hell of it, but want colored text in
a RichTextBox. BUT, I dunno how to do it, cause when I try to switch to a color, it ****s up. Ya, so, help?
Jul 30th, 2006, 08:10
PM #27
rackFanatic Member Join Date: Jul 06Location: Anchorage, AlaskaPosts: 545
Re: RichTextBox Tricks and Tips
When I try to set the xwidth to 3.5 it dosen't not draw a table, the text is all scambled.
I need the width of each cell to be 3.5inch
I need the Height of each cell to be 2inch
I need there to be 2 columns, with 5 rows.
What is the best way to accomplish this?
EDIT:
I got the width correct, I was using 3.5, when I should have been using Twips, 5040.
How do I do the Height of each cell to be exactly 2inches? Or 2880 Twips.
__________________
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows
your question has been answered.
"As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998Jeremy J Swartwood
Last edited by rack; Jul 30th, 2006 at 08:21 PM.
Feb 4th, 2007, 11:01
AM #28
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
Using your example I've come to understand how to have text in a richtextbox act as a hyperlink, but given text
that looks like this (from which I will strip away the URL tags)
[ URL=http://www.vbforums.com/showthread.php?p=11111]this thread[/URL ]
how can I get it to look like this?
this thread
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 12/17
Feb 4th, 2007, 03:48
PM #29
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
All you need to do is mark the text that you want to attach a hyperlink to with the CFE_LINK Effect. You'll have
to keep the URL in a list somewhere so you can respond to user mouse clicks in your WM_NOTIFY event
interception.
See my cool spell checker example for how to do this. The spell checker marks all mispelled words with the
CFE_LINK effect so that when the user right clicks on it spelling suggestions can be made.
BTW this is much better than RobDogg's simple little spell checker
Edit: the link you provided above does not work.
-Bill
Feb 4th, 2007, 05:15
PM #30
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
Thanks for the information Bill. I know about the link; I intentionally made it invalid. BTW, did you get the couple
of emails I sent you?
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 4th,
2007, 05:40 PM #31
MartinLissFormerAdmin/Moderator
Join Date: Sep 99Location: San Jose,CAPosts: 32,308
Re: RichTextBox Tricks and Tips
I just downloaded the clsSpellCheck example and I ran into a problem. When I run it I see the recipe (which I've made
previously BTW ). I click Spell Check and it underlines all the misspellings. However when I double-clicked one of them
nothing happened, so I clicked Spell Check again and got an Invalid property value error in this line
VB Code:
1. 'find each misspelling in the document
2. For Each spError In WordDoc.SpellingErrors
3. iPos = mRTB.Find(spError, iPos + 1, , rtfWholeWord Or rtfMatchCase)
4. [hl="#FFFF80"]mRTB.SelStart = iPos[/hl]
in GetSpellingErrors.
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount • How totrap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to use SaveSetting and GetSetting • Aprogram registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at Last Visited Path • A Blackjack Game • Countlines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • Insert Procedure Names Add-In • A calculator for the gameof Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer • VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Last edited by MartinLiss; Feb 4th, 2007 at 06:02 PM.
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 13/17
Feb 4th, 2007, 07:48
PM #32
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
Okay I have the word "this" in my example above formatted with the CFE_LINK effect and I have the associated
URL stored in a collection and the richtextbox is enabled for AutoURLDetection. How do I actually get the RTB to
open the browser to the stored URL? I assume I have to do something in the RTB's Click event, but what?
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 5th, 2007, 02:04
PM #33
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
I was able to hammer out a way to do it but I'd still be interested in the right way.
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 5th, 2007, 02:33
PM #34
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
The spell checker requires that you right click on a word not double click.
To respond to the user clicking on your hyperlink, see the AutoURL example above.
when text in an RTB has its CFE_LINK effect set, the text will be blue and underlined. More importantly, the RTB
will send a WM_NOTIFY message to its parent form for certain mouse operations on the text.
To respond to these messages (such as a left click) you have to subclass the parent form and intercept these
messages.
So,
1. see the spell check example to see how to set the CFE_LINK effect for text.
2. See the AutoURLDetect example to see how to bring up the browser (or whatever action) when the user clicks
on your special text.
And I did receive your email and even responded.
-Bill
Feb 5th, 2007, 03:00
PM #35
MartinLissFormer Admin/Moderator
Re: RichTextBox Tricks and Tips
Thanks, I've done all that and I basically have it working. I do have a problem though. Take a look at my post
#28. You see that I'm substituting the "Script prompt" that you optionally enter when you insert a hyperlink in a
post for the URL itself, so when the user clicks on the underline-blue word I need to tell VB somehow what the
URL associated with that word is. I've worked that out by storing both pieces of data in a modified version of your
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 14/17
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
MisSpellings collection and I can now get the browser to open to the correct page. My problem is however, what
to do about situations where the same underlined-blue word occurs in more that one place? In that situation
there would likely be different URLs associated with them, so what I'd like to do is store some unique, identifying,
rtf tag before or after the underlined-blue word where that tag would be the index to the proper entry in the
collection. Can I insert things like \'123 into the rtf?
I never received your response to my emails so if you could send me a PM with what you said I'd appreciate it.
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 5th, 2007, 03:52
PM #36
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
Ok I understand your question now. I thought it was strange that I was having to explain things to you that are
spelled out in the example.
Here is an idea:
This \v www.vbforums.com \v0
Feb 5th, 2007, 03:55
PM #37
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
What if there were two URLs and I needed to be able to differentiate them?
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 5th, 2007, 04:25
PM #38
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
My idea is to insert your URL right in the RTF text and hide it with the \v tags.
You can then retrieve this info when the user clicks the adjacent hyperlink.
Does this not work?
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 15/17
Feb 5th, 2007, 05:25
PM #39
MartinLissFormer Admin/Moderator
Join Date: Sep 99Location: San Jose, CAPosts: 32,308
Re: RichTextBox Tricks and Tips
No, that seems like a great idea! I had no idea (until now) what the \v tag did. Is there a comprehesiuve list
someplace of rtf tags?
__________________
Please help me make improvements to the VB Forums Photography ContestTips, Examples & Tutorials:A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount• How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to useSaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at LastVisited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • InsertProcedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer• VBF Photo Contest Winners
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
2009, 2010, 2011
If someone helped you today then please consider rating their post.
Feb 5th, 2007, 06:10
PM #40
moeurOld Member
Join Date: Nov 04Location: In Hiding....Weather: sizzzzlin'........Code: SecretPosts: 2,703
Re: RichTextBox Tricks and Tips
Here is the specification of RTF 1.5
http://www.biblioscape.com/rtf15_spec.htm
Note however that the richtextbox control supports only about 10% of the codes.
I use the vbforums editor to test codes.
Go to View\RTF
Then enter the codes you want to test
Then select View\Normal to see if it worked.
If it didn't work and you go back to View/RTF and the code you entered is gone, then the control does not
support it so it removed it.
Page 1 of 4 1 2 3 4 >
« Previous Thread | Next Thread »
VBForums > VBForums CodeBank > CodeBank - Visual Basic 6 and earlier
RichTextBox Tricks and Tips
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threadsYou may not post repliesYou may not post attachmentsYou may not edit your posts
BB code is OnSmilies are On[IMG] code is OnHTML code is Off
Forum Rules
Forum Jump
CodeBank - Visual Basic 6 and earlier Go
All times are GMT -5. The time now is 10:33 AM.
Contact Us - VB Forums - Archive - Top
MARKETPLACE
Rosetta Stone: New Mobile App foriPadGet Full Access AND the Complete 1-5 LevelSet for just $479 plus FREE Shipping!www.RosettaStone.com
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 16/17
Network Management SoftwareDiscover, Map, Monitor & Manage all networkdevices, Apps, AD, Services, etc. TryFree/Tria l Editionwww.OpManager.com
Rosetta Stone: New Mobile App foriPadGet Full Access AND the Complete 1-5 LevelSet for just $479 plus FREE Shipping!www.RosettaStone.com
Acceptable Use Policy
The Netw ork for Technology Professionals
Search:
About Internet.com
Copyright 2011 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | New sletters | E-mail Offers
Powered by vBulletin® Version 3.8.1Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
7/24/2011 RichTextBox Tricks and Tips - VBForums
www.vbforums.com/showthread.php?t… 17/17