0% found this document useful (0 votes)
820 views17 pages

Rich Text Box Tricks and Tips - VBForums

RichTextBox Tricks and Tips - VBForums IT Professionals Developers Solutions eBook Library Webopedia Login Register To receive newsletters and white papers, use the register button ABOVE.

Uploaded by

Saravana Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
820 views17 pages

Rich Text Box Tricks and Tips - VBForums

RichTextBox Tricks and Tips - VBForums IT Professionals Developers Solutions eBook Library Webopedia Login Register To receive newsletters and white papers, use the register button ABOVE.

Uploaded by

Saravana Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

7/24/2011

RichTextBox Tricks and Tips - VBForums


IT Professionals Developers Solutions eBook Library Webopedia Login Register 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

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 C odeBank > C odeBank - Visual Basic 6 and earlier

RichTextBox Tricks and Tips


Register FAQ Calendar Today's Posts

User Name User Name Password VB Jobs

Remember Me? Log in Search

Page 1 of 4 1 2 3 4 > Thread Tools Display Modes

Aug 19th, 2005, 10:41 AM

#1
RichTextBox Tricks and Tips

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Aug 19th, 2005, 10:43 AM

#2
Highlighting text

moeur
Old Member

Since there is no .SelHighlight property of the RichTextBox control, I created one.


C ode:

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

www.vbforums.com/showthread.php?t

1/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


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 & strRTF = RTB.TextRTF 'add new color bkColor = AddColorToTable(strRTF, 'add highlighting strRTF = Replace(strRTF, "\'9d", strRTF = Replace(strRTF, "\'81", .TextRTF = strRTF .SelStart = iPos End With End Sub

Chr(&H81)

lColor) "\up1\highlight" & CStr(bkColor) & "") "\highlight0\up0 ")

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 table
C ode:

Function AddColorToTable(strRTF As String, lColor As Long) As Integer Dim iPos As Long, jpos As Long Dim Dim Dim Dim Dim Dim Dim Dim ctbl As String tagColors nColors As Integer tagNew As String i As Integer iLen As Integer split1 As String 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
Super and Subscripting

moeur
Old Member

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.

www.vbforums.com/showthread.php?t

2/17

7/24/2011
Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703 C ode:

RichTextBox Tricks and Tips - VBForums


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
Insert Tables

moeur
Old Member

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.

Join Date: Nov 04 Properties - all sizes are in twips Location: In Hiding.... Weather: xLeft - Position of the left edge of the table sizzzzlin'........ C ode: Secret isCentered - Set to True to center the table Posts: 2,703

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 is
C ode:

www.vbforums.com/showthread.php?t

3/17

7/24/2011
Option Explicit

RichTextBox Tricks and Tips - VBForums


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 .Columns = 3 .Rows = 2 'fill the cells 'Row 1 .Cell(1, 1).Contents .Cell(1, 2).Contents .Cell(1, 3).Contents

table

= "Row 1" = "Column2" = "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
Insert Pictures

moeur
Old Member

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 picture
C ode:

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

'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 string
C ode:

www.vbforums.com/showthread.php?t

4/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


'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" 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) 'some temprory file

Attached is code plus the declares


Attached 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
Find and Replace Common Dialog

moeur
Old Member

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.
C ode:

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

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

www.vbforums.com/showthread.php?t

5/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


Full Featured Spell Checker

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Here is an example of use:


C ode:

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 SpellC heck.zip (18.3 KB, 2692 views)

Last edited by moeur; Mar 12th, 2007 at 08:40 PM.

Sep 11th, 2005, 10:58 AM

#8
Get row and column number of cursor

moeur
Old Member

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.
C ode:

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

www.vbforums.com/showthread.php?t

6/17

7/24/2011
Option Explicit

RichTextBox Tricks and Tips - VBForums


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 GetC ursorPos.zip (2.5 KB, 2392 views)

Last edited by moeur; Mar 12th, 2007 at 08:42 PM.

Sep 29th, 2005, 11:48 AM

#9
Auto Detect and respond to URLs

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

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 detection
C ode:

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.
C ode:

www.vbforums.com/showthread.php?t

7/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


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
Re: RichTextBox Tricks and Tips

longwolf
Frenzied Member

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.

Join Date: Oct 02 Posts: 1,343

Oct 3rd, 2005, 05:59 PM

#11
Re: RichTextBox Tricks and Tips

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Jan 16th, 2006, 01:57 PM

#12
Re: RichTextBox Tricks and Tips

JustinW
New Member Join Date: Jan 06 Posts: 2

Hi: First off, thanks so much for posting the codes for inserting tables. That's much appreciated!!!

www.vbforums.com/showthread.php?t

8/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


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
Re: Insert Tables

darki
New Member Join Date: Apr 06 Posts: 3

Hi, very nice codes... I found one bug in RTFtable


VB C ode:

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
Re: RichTextBox Tricks and Tips

moeur
Old Member

Thanks darki

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

May 14th, 2006, 11:24 AM

#15
Re: RichTextBox Tricks and Tips

mamaco
New Member Join Date: May 06 Posts: 1

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

www.vbforums.com/showthread.php?t

9/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


.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
Re: RichTextBox Tricks and Tips

BodwadUK
KING BODWAD XXI

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

Join Date: Aug 02 Location: Nottingham Posts: 2,164

Jun 2nd, 2006, 07:24 PM

#17
Re: RichTextBox Tricks and Tips

moeur
Old Member

Probably the easiest thing to do is lock the window while you are doing the highlighting with LockWindowUpdate.
VB C ode:

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.

Private Declare Function LockWindowUpdate Lib "user32" ( _ ByVal hwndLock As Long) As Long Private Sub Command1_Click() Dim iPos As Integer 'save the current cursor position iPos = RTB.SelStart 'prevent the window from changing LockWindowUpdate RTB.hWnd 'highlight a word RTB.Find "is" HighLight RTB, vbYellow 'restore the cursor position RTB.SelStart = iPos 'unlock the window LockWindowUpdate 0 End Sub

Jun 5th, 2006, 02:48 AM

#18
Re: RichTextBox Tricks and Tips

BodwadUK
KING BODWAD XXI

Thanks I shall give it a go __________________ If you dribble then you are as mad as me Lost World Creations Website (Astrophotography) Lene Marlin

Join Date: Aug 02 Location: Nottingham Posts: 2,164

Jun 5th, 2006, 02:52 AM

#19
Re: RichTextBox Tricks and Tips

BodwadUK
KING BODWAD XXI

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

www.vbforums.com/showthread.php?t

10/17

7/24/2011
Join Date: Aug 02 Location: Nottingham Posts: 2,164

RichTextBox Tricks and Tips - VBForums


Lost World Creations Website (Astrophotography) Lene Marlin

Jun 12th, 2006, 09:47 PM

#20
Re: RichTextBox Tricks and Tips

nokmaster
Fanatic Member Join Date: Nov 02 Location: Philippines Posts: 877

thanks for that tricks.. but how to autoscroll the richtextbox?

Jun 12th, 2006, 11:50 PM

#21
Re: RichTextBox Tricks and Tips

moeur
Old Member

what do you mean by autoscroll? What do you want to do?

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Jun 13th, 2006, 12:05 AM

#22
Re: RichTextBox Tricks and Tips

nokmaster
Fanatic Member Join Date: Nov 02 Location: Philippines Posts: 877

@moeur hi, i mean richtextbox with vertical scroller. if u put this command into command1
VB C ode:

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
Re: RichTextBox Tricks and Tips

BodwadUK
KING BODWAD XXI

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

Join Date: Aug 02 Location: Nottingham Posts: 2,164

Jun 13th, 2006, 04:29 AM

#24
Re: RichTextBox Tricks and Tips Quote:

nokmaster
Fanatic Member Join Date: Nov 02 Location: Philippines Posts: 877

Originally Posted by BodwadUK change selstart to the location you want the cursor. It should scroll for you how?

www.vbforums.com/showthread.php?t

11/17

7/24/2011
Jun 13th, 2006, 05:01 AM

RichTextBox Tricks and Tips - VBForums


#25
Re: RichTextBox Tricks and Tips

BodwadUK
KING BODWAD XXI

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

Join Date: Aug 02 Location: Nottingham Posts: 2,164

Jun 30th, 2006, 06:11 AM

#26
Re: RichTextBox Tricks and Tips

Yuji1
New Member Join Date: Jun 06 Posts: 1

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
Re: RichTextBox Tricks and Tips

rack
Fanatic Member Join Date: Jul 06 Location: Anchorage, Alaska Posts: 545

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 se e the world I wishe d tonight, ne ve r the le ss, sle e p has com e , and de ath shall soo n follow..." 1998 Je re m y J Swartwood

Last edited by rack; Jul 30th, 2006 at 08:21 PM.

Feb 4th, 2007, 11:01 AM

#28
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 ]

Join Date: Sep 99 Location: San Jose, C A Posts: 32,308

how can I get it to look like this? this thread __________________

Please help me make improvements to the VB Forums Photography Contest


Tips, Examples & Tutorials:
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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.

www.vbforums.com/showthread.php?t

12/17

7/24/2011

RichTextBox Tricks and Tips - VBForums

Feb 4th, 2007, 03:48 PM

#29
Re: RichTextBox Tricks and Tips

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

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
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 Contest


Tips, Examples & Tutorials:
Join Date: Sep 99 Location: San Jose, C A Posts: 32,308
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 C ode:

Join Date: Sep 99 Location: San Jose, CA Posts: 32,308

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 Contest


Tips, Examples & Tutorials:
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "o pe n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox R e size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e C ount line s of code Private Me ssage Vie we r C opy/Paste VB C ode Paste VB Code Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo Conte st W inne rs

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.

www.vbforums.com/showthread.php?t

13/17

7/24/2011
Feb 4th, 2007, 07:48 PM

RichTextBox Tricks and Tips - VBForums


#32
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 Contest


Join Date: Sep 99 Location: San Jose, C A Posts: 32,308

Tips, Examples & Tutorials:


A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 Contest


Tips, Examples & Tutorials:
Join Date: Sep 99 Location: San Jose, C A Posts: 32,308
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

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
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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

www.vbforums.com/showthread.php?t

14/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


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. __________________

Join Date: Sep 99 Location: San Jose, C A Posts: 32,308

Please help me make improvements to the VB Forums Photography Contest


Tips, Examples & Tutorials:
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

moeur
Old Member

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

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Feb 5th, 2007, 03:55 PM

#37
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 Contest


Tips, Examples & Tutorials:
Join Date: Sep 99 Location: San Jose, C A Posts: 32,308
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

moeur
Old Member

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?

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

www.vbforums.com/showthread.php?t

15/17

7/24/2011
Feb 5th, 2007, 05:25 PM

RichTextBox Tricks and Tips - VBForums


#39
Re: RichTextBox Tricks and Tips

MartinLiss
Former Admin/Moderator

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 Contest


Tips, Examples & Tutorials:
Join Date: Sep 99 Location: San Jose, C A Posts: 32,308
A valuable forum tool Ge ne rate unique Tre e Vie w k e ys Tre e Vie w with "ope n" and "close d folde r" icons Tim e code using Ge tTick C ount How to trap the Tab k e y Scroll a form Num be rBox Active X control C olor a ListVie w row An InputBox form How to use Save Se tting and Ge tSe tting A program re gistration sche m e Spe llche ck a Te x tbox Re size controls O pe n W indows Ex plore r at Last Visite d Path A Black jack Gam e Count line s of code Private Me ssage Vie we r Copy/Paste VB C ode Paste VB Co de Add-In Inse rt Proce dure Nam e s Add-In A calculator for the gam e of Spide r My re vie w o f R EALbasic 2008 VB6 De bug Tutorial Picture /Vide o Vie we r VBF Photo C onte st W inne rs

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
Re: RichTextBox Tricks and Tips

moeur
Old Member

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.

Join Date: Nov 04 Location: In Hiding.... Weather: sizzzzlin'........ C ode: Secret Posts: 2,703

Page 1 of 4 1 2 3 4 >

Previous Thread | Next Thread VBForums > VBForums C odeBank > C odeBank - Visual Basic 6 and earlier

RichTextBox Tricks and Tips

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

Posting Rules
You You You You may may may may not not not not post new threads post replies post attachments edit your posts

BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

Forum Jump C odeBank - 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 for iPad
Ge t Full Acce ss AND the C om ple te 1-5 Le ve l Se t for just $479 plus FR EE Shipping! www.Rose ttaStone .com

www.vbforums.com/showthread.php?t

16/17

7/24/2011

RichTextBox Tricks and Tips - VBForums


Network Management Software
Discove r, Map, Monitor & Manage a ll ne twork de vice s, Apps, AD, Se rvice s, e tc. Try Fre e /Tria l Edition www.O pManage r.com

Rosetta Stone: New Mobile App for iPad


Ge t Full Acce ss AND the C om ple te 1-5 Le ve l Se t for just $479 plus FR EE Shipping! www.Rose ttaStone .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.1 C opyright 2000 - 2011, Jelsoft Enterprises Ltd.

www.vbforums.com/showthread.php?t

17/17

You might also like