[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Embedding a lable inside a Rich Text Box

JensB

8/25/2011 7:08:00 AM

I have been trying to figure this out for ages and cannot. I need some
help.

I am trying to emulate a standard email address field, where addresses
can be typed in or selected, and once recognised, they are no longer
text.

As far as I can see, this is done by replacing the address with a label
(or something like that) which is embedded in the text at the location
that the address was. The question is how to embed the label. The
documentation on the RTBox.OLEObjects.Add method is spectacularly
unhelpful.

Does anyone have any thoughts, suggestions or articles that they could
point me too as to how to accomplish this.

Or alternatively, if I have got all of this wrong, could you let me
know how it should be done.

--
Michael Cole


10 Answers

MikeD

8/25/2011 5:40:00 PM

0



"Michael Cole" <invalid@microsoft.com> wrote in message
news:j34saf$uss$1@dont-email.me...
> I have been trying to figure this out for ages and cannot. I need some
> help.
>
> I am trying to emulate a standard email address field, where addresses can
> be typed in or selected, and once recognised, they are no longer text.
>
> As far as I can see, this is done by replacing the address with a label
> (or something like that) which is embedded in the text at the location
> that the address was. The question is how to embed the label. The
> documentation on the RTBox.OLEObjects.Add method is spectacularly
> unhelpful.
>
> Does anyone have any thoughts, suggestions or articles that they could
> point me too as to how to accomplish this.
>
> Or alternatively, if I have got all of this wrong, could you let me know
> how it should be done.
>


So what exactly are you asking? It sounds to me as if you just want
hyperlinks in your RTB.

Give this a shot:

http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_frm/thread/41166a233c1a1c79/a97e952c6e837bf1?hl=en&q=hyperlink+richtextbox+group:microsoft....*+author:MikeD


--
Mike


JensB

8/26/2011 12:37:00 AM

0

MikeD brought next idea :
>
> "Michael Cole" <invalid@microsoft.com> wrote in message
> news:j34saf$uss$1@dont-email.me...
>> I have been trying to figure this out for ages and cannot. I need some
>> help.
>>
>> I am trying to emulate a standard email address field, where addresses can
>> be typed in or selected, and once recognised, they are no longer text.
>>
>> As far as I can see, this is done by replacing the address with a label (or
>> something like that) which is embedded in the text at the location that the
>> address was. The question is how to embed the label. The documentation on
>> the RTBox.OLEObjects.Add method is spectacularly unhelpful.
>>
>> Does anyone have any thoughts, suggestions or articles that they could
>> point me too as to how to accomplish this.
>>
>> Or alternatively, if I have got all of this wrong, could you let me know
>> how it should be done.
>>
>
>
> So what exactly are you asking? It sounds to me as if you just want
> hyperlinks in your RTB.
>

No, its not hyperlinks. What I want is an effect, as in Outlook,
whereby validated email addresses are effectively in the RTBox as a
single character: -
- clicking anywhere on them highlights the entire text
- when arrowing forwards and backwards, it acts as a single character
- pressing delete will delete the entire address

In effect, it acts like an embedded picture. Now there is plently of
examples on the internet as to how to embed pictures in RTBoxes, and
how to embed Excel spreadsheets, but nothing about how to embed a label
or other control.

--
Michael Cole


JensB

8/26/2011 7:39:00 AM

0

Michael Cole wrote on 26/08/2011 :
> MikeD brought next idea :
>>
>> "Michael Cole" <invalid@microsoft.com> wrote in message
>> news:j34saf$uss$1@dont-email.me...
>>> I have been trying to figure this out for ages and cannot. I need some
>>> help.
>>>
>>> I am trying to emulate a standard email address field, where addresses can
>>> be typed in or selected, and once recognised, they are no longer text.
>>>
>>> As far as I can see, this is done by replacing the address with a label
>>> (or something like that) which is embedded in the text at the location
>>> that the address was. The question is how to embed the label. The
>>> documentation on the RTBox.OLEObjects.Add method is spectacularly
>>> unhelpful.
>>>
>>> Does anyone have any thoughts, suggestions or articles that they could
>>> point me too as to how to accomplish this.
>>>
>>> Or alternatively, if I have got all of this wrong, could you let me know
>>> how it should be done.
>>>
>>
>>
>> So what exactly are you asking? It sounds to me as if you just want
>> hyperlinks in your RTB.
>>
>
> No, its not hyperlinks. What I want is an effect, as in Outlook, whereby
> validated email addresses are effectively in the RTBox as a single character:
> -
> - clicking anywhere on them highlights the entire text
> - when arrowing forwards and backwards, it acts as a single character
> - pressing delete will delete the entire address
>
> In effect, it acts like an embedded picture. Now there is plently of
> examples on the internet as to how to embed pictures in RTBoxes, and how to
> embed Excel spreadsheets, but nothing about how to embed a label or other
> control.

OK, I've been playing with this all day, and I have got to the
following: -

If I put the following in the RTF field: -

{\field \fldlock {\*\fldinst QUOTE "blah"}{\fldrslt blah}}

then theoretically it should act as a field. But it isn't - it is
still allowing the field contents to be directly typed in.

Anyone know anything about RTF?


--
Michael Cole


mikeb

8/26/2011 11:46:00 AM

0


"Michael Cole" <invalid@microsoft.com> wrote in message
news:j37ihc$og7$1@dont-email.me...
> Michael Cole wrote on 26/08/2011 :
>> MikeD brought next idea :
>>>
>>> "Michael Cole" <invalid@microsoft.com> wrote in message
>>> news:j34saf$uss$1@dont-email.me...
>>>> I have been trying to figure this out for ages and cannot. I need some
>>>> help.
>>>>
>>>> I am trying to emulate a standard email address field, where addresses
>>>> can be typed in or selected, and once recognised, they are no longer
>>>> text.
>>>>
>>>> As far as I can see, this is done by replacing the address with a label
>>>> (or something like that) which is embedded in the text at the location
>>>> that the address was. The question is how to embed the label. The
>>>> documentation on the RTBox.OLEObjects.Add method is spectacularly
>>>> unhelpful.
>>>>
>>>> Does anyone have any thoughts, suggestions or articles that they could
>>>> point me too as to how to accomplish this.
>>>>
>>>> Or alternatively, if I have got all of this wrong, could you let me
>>>> know how it should be done.
>>>>
>>>
>>>
>>> So what exactly are you asking? It sounds to me as if you just want
>>> hyperlinks in your RTB.
>>>
>>
>> No, its not hyperlinks. What I want is an effect, as in Outlook, whereby
>> validated email addresses are effectively in the RTBox as a single
>> character: -
>> - clicking anywhere on them highlights the entire text
>> - when arrowing forwards and backwards, it acts as a single character
>> - pressing delete will delete the entire address
>>
>> In effect, it acts like an embedded picture. Now there is plently of
>> examples on the internet as to how to embed pictures in RTBoxes, and how
>> to embed Excel spreadsheets, but nothing about how to embed a label or
>> other control.
>
> OK, I've been playing with this all day, and I have got to the
> following: -
>
> If I put the following in the RTF field: -
>
> {\field \fldlock {\*\fldinst QUOTE "blah"}{\fldrslt blah}}
>
> then theoretically it should act as a field. But it isn't - it is still
> allowing the field contents to be directly typed in.
>
> Anyone know anything about RTF?
>

http://msdn.microsoft.com/en-us/librar...(office.10).aspx

> --
> Michael Cole
>
>


Mayayana

8/26/2011 2:18:00 PM

0

You've probably already considered this, but I wonder
about just processing actions as they happen. There
are options like EM_FINDWORDBREAK to find the beginning
and end of the "word" you're in at click. From there it
shouldn't be hard to test for a valid email address and
then select the text, etc. The operations are simple
enough that they should be feasible to do instantly at
every click. (Instant in human terms, at any rate.)



JensB

9/1/2011 12:42:00 AM

0

Mayayana wrote on 27/08/2011 :
> You've probably already considered this, but I wonder
> about just processing actions as they happen. There
> are options like EM_FINDWORDBREAK to find the beginning
> and end of the "word" you're in at click. From there it
> shouldn't be hard to test for a valid email address and
> then select the text, etc. The operations are simple
> enough that they should be feasible to do instantly at
> every click. (Instant in human terms, at any rate.)

This is what I have eventually ended up doing. Even still, it leaves
some issues, but it works. You also find out that the RTB is buggy.

One of many such interesting issues: -
Create a form, and add a RichTextBox to it.

Put this code in: -

RichTextBox.TextRTF = "A" & Chr$(160) & "B" 'Non-breaking space
Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))
RichTextBox.TextRTF = RichTextBox.TextRTF
Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))

Have a guess what the two debug statements print out...

Fun, fun, fun...

--
Michael Cole


Mayayana

9/1/2011 2:19:00 AM

0


| RichTextBox.TextRTF = "A" & Chr$(160) & "B" 'Non-breaking space
| Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))
| RichTextBox.TextRTF = RichTextBox.TextRTF
| Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))
|

Interesting. It turns a 160 into a 32. I didn't know there
were things like that built in. (Though I know IE is a disaster in
that regard. It does wacky things like turning <B> to <STRONG>
and adding an arbitrary DOCTYPE tag if one uses IE to save a
webpage.) But I wonder why you're using Chr 160. I use
that in HTML but wasn't aware of any difference when used in
other situations.

You might also consider using a system RichEdit, if you're
not already doing so. The VB RTB wraps RichEdit v. 1, which
is "emulated" in recent Windows versions for compatibility. Later
versions provide more options, like multiple undo. (And, one
would like to think, they may have improved functionality in
general.)

I have a version that I wrote using Paul Caton's self-
subclassing code (which he later rewrote to be very concise).

http://www.jsware.net/jsware/v...

I think vbAccelerator also has a version, and Eduardo Morcillo
may have a version. But it's not worth the trouble using
something like vbAccelertor's subclassing DLL. With self-
subclassing a userControl can handle it's own WindowProc
function, as well as the WindowProc function for an API-drawn
RichEdit window. And there are no crashing-in-the-IDE problems.
The result is something that's as easy to use as a VB RTB; one
can use any number of them without additional work; and the
resulting RT window can be v. 3 or later. (V. 3 is supported, I
think, on everything from Win98SE up.)


Jim Mack

9/1/2011 12:36:00 PM

0

Mayayana wrote:
>> RichTextBox.TextRTF = "A" & Chr$(160) & "B" 'Non-breaking space
>> Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))
>> RichTextBox.TextRTF = RichTextBox.TextRTF
>> Debug.Print Asc(Mid(RichTextBox.Text, 2, 1))
>>
>
> Interesting. It turns a 160 into a 32. I didn't know there
> were things like that built in.

RTF is fundamentally 7-bit, but (160) has the 8th bit set. It's not
surprising to me that the high bit gets stripped off, but I've never
tested to see if that happens to all such characters. Anyone tried
Chr(161)?

--
Jim Mack
Twisted tees at www.cafepress.com/2050inc
"We sew confusion"

JensB

9/2/2011 12:22:00 AM

0

Mayayana explained :

> ...But I wonder why you're using Chr 160. I use
> that in HTML but wasn't aware of any difference when used in
> other situations.

It means that when the text wraps, it doesn't break. You don't want
email addresses being split over two lines.

> You might also consider using a system RichEdit, if you're
> not already doing so. The VB RTB wraps RichEdit v. 1, which
> is "emulated" in recent Windows versions for compatibility. Later
> versions provide more options, like multiple undo. (And, one
> would like to think, they may have improved functionality in
> general.)
>
> I have a version that I wrote using Paul Caton's self-
> subclassing code (which he later rewrote to be very concise).
>
> http://www.jsware.net/jsware/v...

Thanks, I'll have a look.

--
Michael Cole


Raoul Watson

9/11/2011 4:01:00 PM

0

On 8/26/2011 3:39 AM, Michael Cole wrote:
> Michael Cole wrote on 26/08/2011 :
>> MikeD brought next idea :
>>>
>>> "Michael Cole" <invalid@microsoft.com> wrote in message
>>> news:j34saf$uss$1@dont-email.me...
>>>> I have been trying to figure this out for ages and cannot. I need
>>>> some help.
>>>>
>>>> I am trying to emulate a standard email address field, where
>>>> addresses can be typed in or selected, and once recognised, they are
>>>> no longer text.
>>>>
>>>> As far as I can see, this is done by replacing the address with a
>>>> label (or something like that) which is embedded in the text at the
>>>> location that the address was. The question is how to embed the
>>>> label. The documentation on the RTBox.OLEObjects.Add method is
>>>> spectacularly unhelpful.
>>>>
>>>> Does anyone have any thoughts, suggestions or articles that they
>>>> could point me too as to how to accomplish this.
>>>>
>>>> Or alternatively, if I have got all of this wrong, could you let me
>>>> know how it should be done.
>>>>
>>>
>>>
>>> So what exactly are you asking? It sounds to me as if you just want
>>> hyperlinks in your RTB.
>>>
>>
>> No, its not hyperlinks. What I want is an effect, as in Outlook,
>> whereby validated email addresses are effectively in the RTBox as a
>> single character: -
>> - clicking anywhere on them highlights the entire text
>> - when arrowing forwards and backwards, it acts as a single character
>> - pressing delete will delete the entire address
>>
>> In effect, it acts like an embedded picture. Now there is plently of
>> examples on the internet as to how to embed pictures in RTBoxes, and
>> how to embed Excel spreadsheets, but nothing about how to embed a
>> label or other control.
>
> OK, I've been playing with this all day, and I have got to the following: -
>
> If I put the following in the RTF field: -
>
> {\field \fldlock {\*\fldinst QUOTE "blah"}{\fldrslt blah}}
>
> then theoretically it should act as a field. But it isn't - it is still
> allowing the field contents to be directly typed in.
>
> Anyone know anything about RTF?
>
>

If you can find an email with such link, you can save it as RTF. SImply
open it with notepad or a hex editor to see how it's done.