RichTextBox and Emdashes

M

Mike

Emdashes are frequently used in our application. Although the \emdash is
supported by the RTF specification, the RichTextBox in VB.Net (2005) does not
recognize this tag.

As we have an existing database of items which were developed under VB6 when
this tag was recognized, a workaround is to convert the \emdash to a \'97
which does display as an emdash (in most fonts and in the ones we use).

Here's the problem - we have a TextFindAndReplace function displayed as a
separate dialogue w/numerous options. To allow the user to FindNext in the
richtextbox, we must set the HideSelection property of the richtextbox to
False, so the user can see what's found.

However, as soon as this property is set, our replacement codes for the
emdashes are lost and hyphens are displayed.

To recreate this - set up a new WindowsApplication and place a richtextbox
and button on the form. Then copy the code below to the Form1 class.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim rtfString As String =
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0
Arial;}}" & _
"{\*\generator Msftedit
5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 Here's an emdash \emdash and
here's another one \emdash\par" & _
"\par}"

rtfString = rtfString.Replace("\emdash", "\'97")
RichTextBox1.Rtf = rtfString

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.HideSelection = False
End Sub

Any suggestions to work around this issue would be appreciated.

Thanks.
 
M

Mike

Thanks very much Andrew! I was unaware of the horizontal bar character.

This does the trick in the test app and I think it can be worked into the
app w/o too much grief.

Thanks again,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top