How to scroll label control along with text in RichTextBox

  • Thread starter Thread starter zafar
  • Start date Start date
Z

zafar

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
 
zafar said:
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
 
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 ridof
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.btnMov2.GetPositionFromCharIndex
(Me.btnMov2.TextLength)
Me.btnMov2.Controls.Add(LinkLabel1)
Me.btnMov2.AppendText(LinkLabel1.Text & " This is appeanded
text after the link lable" & vbNewLine & "Another line to rich text
box")
 
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")
 
zafar said:
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
 
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 firingan
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.

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