I am trying to adjust you code to make it an option that can be turned on/off.
If the user opens the Options form and changes the option from Enabled to Disabled, I am getting the error: Object variable or With block variable not set.
on this line:
vb Code:
FormSubClass.Unsubclass
I know what this means, but I'm not too sure how to change this.
This is because, even if the Enabled option is selected, I don't use this line until certain conditions are met:
vb Code:
EnableAutoURLDetection RTB
so the RTB hasn't yet been subclassed.
Is there some way of checking if the subclassing has happened before I fire this line of code?
vb Code:
FormSubClass.Unsubclass
Such as
Code:
If Not FormSubClass.Unsubclass Then ....
If somebody helps you, take time to RATE the post. I do.
"FAILURE IS NOT AN OPTION. It comes bundled with the software."
Below are some of the threads that have helped me along the way:
I have used your Auto URL Detection within my program. When i downloaded your file it worked fine on its own, but as soon as I have intergrated it with mine I seem to have broken it.
My program still work as it did, and the url changes to a hyperlink where expected, the only bit which does not work is th clicking of the url.
Can you look over what I have done and see what you make of it
Martin
Thanks for your offer of help. What a great site you have got here.
I have rewritten this part of my program in a single form removing it from my main program in order to send to you for help and in so, I have resolved my issue.
I have changed my program to look at the SQL Northwind default database. If you change a couple of the records within the orders table on the "Shipname" field to be a url then this seems to work fine.
I have attached for others to view.
If you are going to look at the attached please be aware that my coding maybe a little rough around the edges
Thank you for these great RTB tips. I have been using the Tables code you provided. As I'm sure you're aware, there are two basic wrappers for RTB control... riched32.dll and riched20.dll. The tables code behaves differently depending on the wrapper being used. The problems I've noted are:
1. Text that wraps in a cell does not display properly if riched32.dll (default) is being used. It displays correctly with the newer riched20.dll (ver 4+).
2. The grid lines of a table created with your code does not print with riched20.dll but does with the older riched32.dll.
Since MS WordPad uses the riched20.dll (disguised as msftedit.dll) and since the tables format correcly, I too prefer that version. My question is... is there a way to have the grid lines print?
Thanks, again for your insight and very helpful code!
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!
Hi there, wanted to try your spell checker but faced some strange issues. I copied over your libraries and imported your form, but for the same actions I am getting error at GetSpellingErrors()
For Each spError In WordDoc.SpellingErrors
Error 13 Type mismatch
whenever there is a misspelled word. If there are no errors, the program works fine. This error only happens to the new 'copied' project, does not happen in your program.
I have added the components and references, even the dll even though I don't think that is needed. I have added the error image attachment here for clearer understanding (if I had not made myself clear)
Has anyone deviced any method / subclass trick for actually changing the default blue color of the RTF EN_LINK hyperlinks? I mean, if I want to display a red hyperlink, is this possible?
In my research I tried using GetSystemColors and SetSystemColors with index value 26 (Hyperlink) but it seems to have no affect of RichEdit.
Thank you very much for the code for the tables in richtextbox, it's the only available on the internet. Unfortunatly i'm using vb.net 2005 and can't convert it correctly to use it in my app. Do you have any library for .net?
I ran into an issue. If I enable the autourldetection the selchange event doesn't fire so the line and columns dont get updated in the statusbar as I move the cursor
I did verify the problem you see. This is a problem with the Richtext box which we have no control over. But, there is a simple fix:
Place the code that is in the SelChange Event in both the RTB_Click and RTB_KeyUp events.
I think you can solve a little problem for me, back in May last year and in another Forum, I was struggling to help someone who wanted something like a ProgressBar but with text inside it (they were building a Browser and wanted to do like Firefox, I think, the Progress was displayed where the URL was typed.) Anyway, I came up with a RichTextBox solution:
Code:
Option Explicit
'
' Example of manipulating RTF in a RichTextBox
' to simulate a 'ProgressBar' with imbedded text
' (Based on some code I found on the Internet somewhere)
'
' Requires:
' Command Button (cmdGo)
' RichTextBox (rtb1)
' Timer (Timer1)
'
' Tested on XP SP2 and it seems to work OK
' Tested on Windows ME and doesn't work
'
Private boFinished As Boolean
Private strOriginalRTF As String
Private Sub cmdGo_Click()
'
' Simulates starting something going
'
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 500
rtb1.Text = "This is some text"
End Sub
Private Sub Timer1_Timer()
'
' Simulates 'progress'
' Triggers once every half second
'
boFinished = UpdateProgress(1)
If boFinished = True Then
Timer1.Enabled = False
rtb1.TextRTF = strOriginalRTF
rtb1.SelStart = 0
rtb1.SelLength = 0
End If
End Sub
Private Function UpdateProgress(intColour As Integer) As Boolean
'
' Progressively change the background colour of
' each character in the RichTextBox to intColour
' Achieved by inserting RTF codes to define a ColorTable
' and highlight the selected text.
'
' Returns True when all characters have been processed
'
Dim strColour As String
Dim strRTF As String
Static intEnd As Integer
UpdateProgress = False
'
' Save the original TextRTF so it can be
' re-set later, increment the character position
' and check if we've finsihed yet
'
If intEnd = 0 Then strOriginalRTF = rtb1.TextRTF
intEnd = intEnd + 1
If intEnd <= Len(rtb1.Text) Then
'
' Select the appropriate number of characters
' and make sure they don't appear highlighted
' by the selection
'
rtb1.SelStart = 0
rtb1.SelLength = intEnd
rtb1.SelColor = rtb1.BackColor
'
' Convert the colour to RGB form
' and insert leading zeros if required
'
strColour = Hex(QBColor(intColour))
strColour = String(6 - Len(strColour), "0") & strColour
'
' Now build our RTF:
'
' ColorTable:
'
strRTF = "{{\colortbl;"
strRTF = strRTF & "\red" & CInt("&H" & Right(strColour, 2))
strRTF = strRTF & "\green" & CInt("&H" & Mid(strColour, 3, 2))
strRTF = strRTF & "\blue" & CInt("&H" & Left(strColour, 2))
strRTF = strRTF & ";}"
'
' Highlight:
' This is the RTF Code used to cause the change in
' colour. It uses our ColorTable (Number 1)
' (I can't seem to find any documentation on this
' code but if it works then ....)
'
strRTF = strRTF & "\highlight1 "
'
' Finally the actual text and closing RTF brackets
'
strRTF = strRTF & Mid(rtb1.Text, 1, intEnd)
strRTF = strRTF & "}}"
'
' Set the RTF of the selected characters to our
' codes
'
rtb1.SelRTF = strRTF
Else
'
' We've finished
'
UpdateProgress = True
intEnd = 0
End If
End Function
Was it, perhaps some of your code I stumbled upon. The 'highlight' thing has had me confused for a long time !!
Thanks so much for posting these helpful RTB functions. I would like your permission to use modRTFpic.bas in a commercial application. How would you like me to credit you in the comments?
Thanks so much for posting these helpful RTB functions. I would like your permission to use modRTFpic.bas in a commercial application. How would you like me to credit you in the comments?
This was posted in 2007, so he might not still be active, plus since he posted it here he is giving everyone permission to use it, its open.
So give him credits if you want but its not required - at least i dont think so
I have a unique question that may compliment this thread.
I need to highlight a line in a richtextbox only if "line starts with" mystring...
The code needs to fire as user is typing...
I store my search strings and unique highlight colors thus:
Code:
Dim searchword() As String = {"fox", "dog", "cat", "horse"}
Dim ItemBkColor() As Color = {Color.Yellow, Color.LightYellow, Color.PaleVioletRed, Color.LightSeaGreen}
Please can you show me how to code the richtextbox events to catch this scenario ?
hi moeur i am using your modRTFpic.bas in my server/client to handle smilies.it is working fine in the send part but while receiving i get a code such as
I would have to see the relevant sections of your code to be of any help.
here , i have uploaded a rough project . i can send smileys from my server to the client and out put them on a textbox but when i send smileys and a message together i am not able to output smileys
Last edited by pannam; Jul 30th, 2008 at 11:51 AM.
I don't see where you are using my code.
Perhaps you should talk to the hand.
i got it solved (a silly mistake) .A big thanks to you, as this post got me started and i learned a lot from this post and your project as well ..all in all i got so confused i uploaded a different project .sorry .
lastly ,
great work
moeur, thanks for all your work and these valuable tips.
I am trying to create a module which will actually create a RTF file (document).
To do this, I am writing RTF control words and codes out to the file.
I am able to do it for plain text, and colored text, and pictures/images,
and lines and rectangles.
But for ROTATED text (text which is NOT horizontal, but lies at an angle on the page), I am bumping into a brick wall.
I have been able to "sort of" solve this by creating a temporary picture object with the rotated text in it, then writing that picture out to the RTF.
This works, but it is somewhat clumsy... and my determination of the picture dimensions, based on the angle of text rotation is really clumsy.
So I am looking for an alternative.
I am looking at the code details of an RTF file which has rotated text in it.
It uses a "shape", and then inserts a long string of hex data after all the appropriate codes. And this does it just fine.
So, to my question,
do you have any further info on the format/content of the hex string which I might be able to use to employ this solution, rather than my picture box ?
I enclose a direct copy/paste of the rtf file which contains the "shape" code and which seems to work.
Private Sub AppendText(RTB As RichTextBox, _
fontN As String, _
fontS As Integer, _
fontI As Boolean, _
fontU As Boolean, _
fontB As Boolean, _
NewText As String, _
Optional TextColor As Long = vbBlack)
With RTB
.SelStart = Len(.Text)
.SelColor = TextColor
.SelBold = fontB
.SelItalic = fontI
.SelUnderline = fontU
.SelFontName = fontN
.SelFontSize = fontS
.SelText = vbCrLf & NewText
End With
End Sub
moeur:
I downloaded your program to make tables in RichTextBox.
I am using It in a program I'm developing; when I run my program It writes the new table, but It repeats the table that was in the RichTextBox. How do I delete the first table and show only the new table?
I'm trying to get the spell check to work, all is OK except for right-click to display menu of suggestions. I think this is because all my RTBs are within various pages of SSTab controls on my forms, so the RTB's parent is not the form itself.
I tried some basic changes to clsSpellCheck, such as hard-coding frmxxxx.hwnd rather than mRTB.Parent.hwnd, but with no success.
Am I wasting my time trying to do this with RTBs contained within SSTabs rather than directly within the form?
Last edited by ycdbsoya; Jun 26th, 2009 at 09:21 PM.
The code is really neat and it works.
Unfortunately it disables the RTB's Change and SelChange events, and I need at least the Change Event to enable the Save button in my Toolbar and to ask for to save changes on exit.
Any solutions?
KeyPress and tracking text length between saves/status checks should work for you. The only case it won't work is when someone pastes and cuts texts of exact length by using mouse only. I'd say that is pretty rare. If you use a custom context menu or disable it then this too becomes a non-issue.