Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #514

Re: RichEdit control question

From "Mike Williams" <Mike@WhiskyAndCoke.com>
Newsgroups comp.lang.basic.visual.misc
Subject Re: RichEdit control question
Date 2011-10-19 18:26 +0100
Organization A noiseless patient Spider
Message-ID <j7n167$dvt$1@dont-email.me> (permalink)
References (9 earlier) <j7if8n$71l$1@dont-email.me> <j7iheb$455$1@speranza.aioe.org> <j7ishj$bnc$1@dont-email.me> <j7k2n1$492$1@dont-email.me> <j7mlet$r6v$1@dont-email.me>

Show all headers | View raw


"Mayayana" <mayayana@invalid.nospam> wrote in message 
news:j7mlet$r6v$1@dont-email.me...

> You could just maintain a numeric record of offset and
> length of each hidden text section, but that would have to
> update for each change in the RTB. In my experience it's
> by far the fastest and easiest to tokenize the RTF text.

Thinking along similar lines, and just for fun really, I had a go at doing 
what I thought the OP was originally after. I originally thought he had a 
rtf file that contained hidden words and that he wanted to hide and unhide 
those words in such a way that the rtf file would not have its hidden 
markers removed on the unhide action, so that both hide and unhide would 
work whether or not the hidden words matched a specific pattern or not.

Clearly MS Word uses a simple extra toggle to determine whether it will draw 
the hidden text or not. I'm fairly sure that such a toggle is not available 
in a RichEdit Control and I have no idea of how to intercept a RichEdit 
Control's methods (kind of subclass) in order to achieve the same effect. 
So, I had the idea of using a couple of rtf control words which are not 
actually used and which are normally ignored by a RichEdit Control (a couple 
of animtext control words) and to replace the \v and \v0 control words with 
those in order to unhide the 'hidden' words or phrases. The opposite of 
hiding them again can be then be achieved by replacing the animtext control 
words with the \v and \v0 control words again, so we have a simple toggle 
effect.

What I've got so far is just the bare bones of it and I'm sure there will be 
some 'gotchas' that I haven't yet thought of, but it seems to work so far. 
In the following testbed code I am simply using the VB Replace function to 
switch the markers, and clearly this will have the effect of also switching 
any literal '\v' (etc) in the file. That should be able to be fixed though 
by casting the rtf to a Byte array and running through the Byte array in a 
more flexible way. For example, I think (?) that we can tell whether a \v is 
a literal or a control word by examining the number of contiguous preceeding 
backslashes (if there are any) to determine whether it is an odd or even 
number. Anyway, for what it's worth, here is my simple testbed code as it 
currently stands. You'll need to paste it into a VB Form containing two 
Command Buttons and a RichTextBox and then alter the LoadFile line to load a 
.rtf file that exists on your own system, preferably (for test purposes) a 
rtf file that you have created in MS Word or something similar and in which 
you have selected and hidden a large number of words and part words and 
phrases. Clicking the two Command Buttons should toggle the hidden words on 
and off in the RichTextBox. I'm using a RichTextBox for simplicity, rather 
than a RichEdit Control.

Mike

Option Explicit

Private Sub Form_Load()
Dim s1 As String
RichTextBox1.LoadFile "c:\temp2\test2.rtf"
End Sub

Private Sub Command1_Click()
' unhide
Dim s1 As String
s1 = RichTextBox1.TextRTF
s1 = Replace(s1, "\v\", "\animtext1\")
s1 = Replace(s1, "\v ", "\animtext1 ")
s1 = Replace(s1, "\v0 ", "\animtext2 ")
RichTextBox1.TextRTF = s1
End Sub

Private Sub Command2_Click()
' hide
Dim s1 As String
s1 = RichTextBox1.TextRTF
s1 = Replace(s1, "\animtext1\", "\v\")
s1 = Replace(s1, "\animtext1 ", "\v ")
s1 = Replace(s1, "\animtext2 ", "\v0 ")
RichTextBox1.TextRTF = s1
End Sub


Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-10 14:41 -0700
  Re: RichEdit control question "Nobody" <nobody@nobody.com> - 2011-10-11 00:53 -0400
  Re: RichEdit control question BTIS Jeff <btisjb@gmail.com> - 2011-10-11 08:17 -0700
    Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-11 14:17 -0700
      Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-11 22:27 +0100
        Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-11 14:59 -0700
          Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-12 08:00 +0100
            Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-12 16:18 -0700
              Re: RichEdit control question Deanna Earley <dee.earley@icode.co.uk> - 2011-10-13 08:45 +0100
              Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-13 10:24 +0100
              Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-13 11:41 +0100
              Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-13 13:30 +0100
  Re: RichEdit control question Eric Coleman <eric@strategon.com> - 2011-10-13 19:55 -0500
    Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-14 09:30 +0100
    Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-15 07:53 -0700
      Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-15 17:03 +0100
      Re: RichEdit control question ralph <nt_consulting64@yahoo.net> - 2011-10-15 12:25 -0500
        Re: RichEdit control question ralph <nt_consulting64@yahoo.net> - 2011-10-15 12:29 -0500
        Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-15 12:45 -0700
          Re: RichEdit control question ralph <nt_consulting64@yahoo.net> - 2011-10-15 15:24 -0500
          Re: RichEdit control question "Thorsten Albers" <gudea@gmx.de> - 2011-10-15 23:16 +0000
            Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-16 18:21 -0700
              Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-16 23:15 -0400
              Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-17 17:19 -0400
                Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-17 15:59 -0700
                Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-17 19:59 -0400
                Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-17 17:34 -0700
                Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-17 23:46 -0400
                Re: RichEdit control question Kalkidas <eat@joes.pub> - 2011-10-18 07:35 -0700
                Re: RichEdit control question "Thorsten Albers" <gudea@gmx.de> - 2011-10-18 15:17 +0000
                Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-19 10:09 -0400
                Re: RichEdit control question "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-10-19 18:26 +0100
          Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-15 19:53 -0400
            Re: RichEdit control question "Thorsten Albers" <gudea@gmx.de> - 2011-10-16 03:32 +0000
              Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-16 12:02 -0400
                Re: RichEdit control question "Thorsten Albers" <gudea@gmx.de> - 2011-10-16 22:10 +0000
                Re: RichEdit control question "Mayayana" <mayayana@invalid.nospam> - 2011-10-16 19:17 -0400
                Re: RichEdit control question "Thorsten Albers" <gudea@gmx.de> - 2011-10-17 09:43 +0000

csiph-web