From: Family Tree Mike on


"zafar" wrote:

> On Dec 29, 10:27 pm, zafar <zafarz...(a)hotmail.com> wrote:
> > On Dec 29, 10:08 am, "Scott M." <s-...(a)nospam.nospam> wrote:
> >
> >
> >
> > > "zafar" <zafarz...(a)hotmail.com> wrote in message
> >
> > >news:6c93b1fd-b9f3-4029-bea9-3bd91830ceb3(a)c3g2000yqd.googlegroups.com...
> >
> > > > Hi,
> > > > I have added a label control in RichTextBox, but when text increases
> > > > and scroll bar appears, the label control does not scroll with the
> > > > text.... Can any body suggest a solution for this...
> >
> > > > I will be really thanhfull
> >
> > > > Regards,
> > > > Zafar
> >
> > > A RichTextBox can't contain a Label control, nor does it need to. All
> > > you've done is placed your Label control *over* the RichTextBox control..
> >
> > > Why not just have any text you were going to put into the Text property of
> > > your Label, simply put into the Text property of the RTB and then get rid of
> > > the Label alltogether?
> >
> > > -Scott
>
> Using the following code, I have added a linkedLabel in the
> richTextBox (the linkLabel is not created runtime), and it appears at
> right place, but does not scroll when moving up and down in RTB.
>
> LinkLabel1.Text = "Press Here"
> LinkLabel1.AutoSize = True
> LinkLabel1.Location =
> Me.RichTextBox1.GetPositionFromCharIndex (Me.RichTextBox1.TextLength)
> Me.RichTextBox1.Controls.Add(LinkLabel1)
> Me.RichTextBox1.AppendText(LinkLabel1.Text & " This is
> appeanded text after the link lable" & vbNewLine & "Another line to
> rich text box")
>
> .
>

Again, as Scott said, you have put the label in front of the RichTextBox.

The RTB only scrolls the contents of the .Text property, not any controls
that happen to be in front of it.

Mike

From: zafar on
On Dec 29, 11:19 pm, "Captain Jack" <CaptainJack1...(a)comcast.net>
wrote:
> "zafar" <zafarz...(a)hotmail.com> wrote in message
>
> news:ccae938b-c305-4e77-ba05-87d6777965df(a)d21g2000yqn.googlegroups.com...
> On Dec 29, 10:27 pm, zafar <zafarz...(a)hotmail.com> wrote:
>
> >Using the following code, I have added a linkedLabel in the
> >richTextBox (the linkLabel is not created runtime), and it appears at
> >right place, but does not scroll when moving up and down in RTB.
>
> >  LinkLabel1.Text = "Press Here"
> >  LinkLabel1.AutoSize = True
> >  LinkLabel1.Location =
> >Me.RichTextBox1.GetPositionFromCharIndex (Me.RichTextBox1.TextLength)
> >  Me.RichTextBox1.Controls.Add(LinkLabel1)
> >  Me.RichTextBox1.AppendText(LinkLabel1.Text & " This is
> >appeanded  text after the link lable" & vbNewLine & "Another line to
> >rich text box")
>
> While the RichTextBox control can host other Controls, the drawing surface
> internal to it (where the text is displayed) doesn't offer an access for
> adding controls. So, unfortunately, the LinkLabel doesn't move any more than
> the scroll bars themselves do.
>
> I accomplished something functionally similar to this once, by setting the
> color of the text that I wanted to be linked. When the special text was
> clicked, I used the GetCharIndexFromPosition method to find out the closest
> character clicked, then I looked the index up in a list I made at the time
> of populating the text of the control.
>
> That doesn't give you the functionality of a LinkLabel in terms of firing an
> event of its own or highlighting the text when the mouse enters, but it's
> something. It might be possible to trap the MouseMove event of the
> RichTextBox, and determine what the closese character to the mouse is, and
> change the forecolor and/or underline properties of the text at that point,
> but I've never tried it.
>
> I don't think the RichTextBox gives enough information to do this, but if
> you really need to use the actual LinkLabel, you could try to intercept the
> VScroll event of the RichTextBox and then try to re-position the label
> yourself. You may have to play around with it so it doesn't sit on top of
> the horizontal scroll bar, if you use one.
>
> Another, completely different, option would be to try the WebBrowser
> control. Replace the RichTextBox with that, then stick your text in as HTML,
> and your link text as an anchor. That may get you what you need to
> accomplish, without having to use the RichTextBox at all.
>
> --
> Jack

Thanks alot Jack, that was really helpful suggestion. I really
appreciate your detail response. And hopefully I will find a solution
using your tips.