I want to add LinkLabel-s at the end of the text in RichTextBox control.I do that with this code:

int index = richTextBox1.Text.Length;
Point position = richTextBox1.GetPositionFromCharIndex(index);
LinkLabel label = new LinkLabel();
label.Text = "whatever";
label.AutoSize = false;
label.Location = position;
label.LinkBehavior = LinkBehavior.NeverUnderline;
richTextBox1.Controls.Add(label);

The problem here is that i do not know how to add text right after the last added LinkLabel,i.e. i want when add LinkLabel to move the caret next to the LinkLabel.How to do that?

Reference below(sample---add LinkLabel into ListBox):

for (int i = 0;i < 3;i++)
{
LinkLabel ll = new LinkLabel();
ll.Name = "test"+i;
ll.Text = ll.Name;
ll.Location = new Point(0,i*ll.Height);
this.listBox1.Controls.Add(ll);
Console.WriteLine(ll.Location);
ll.LinkClicked +=
new LinkLabelLinkClickedEventHandler(this.linkClicked);
}

This answer's key is the Location attribute of the public class
System.Windows.Forms.Control,if you are familiar with this
attribute then would not have the question at all.

This answer's key is the Location attribute of the public class
System.Windows.Forms.Control,if you are familiar with this
attribute then would not have the question at all.

when there are too many LinkLabel lines in the ListBox control,
then you must add "this.listBox1.Items.Add(ll);" under the above
code "this.listBox1.Controls.Add(ll);" because of this can help
the ListBox control to show the vertical scrollbar.

when there are too many LinkLabel lines in the ListBox control,
then you must add "this.listBox1.Items.Add(ll);" under the above
code "this.listBox1.Controls.Add(ll);" because of this can help
the ListBox control to show the vertical scrollbar.

The entire code is:

this.listBox1.DrawMode = DrawMode.OwnerDrawFixed;
this.listBox1.ItemHeight = new LinkLabel().Height;
for (int i = 0;i < 55;i++)
{
LinkLabel ll = new LinkLabel();
ll.Name = "test"+i;
ll.Text = "test"+i;
ll.Location = new Point(0,i*ll.Height);
this.listBox1.Controls.Add(ll);
this.listBox1.Items.Add(ll);
Console.WriteLine(ll.Location);
ll.LinkClicked +=
new LinkLabelLinkClickedEventHandler(this.linkClicked);
}

Hi,

sorry for me horrible english, but I have one question.

It is possible detected which (automaticaly generated) linklabel is clicked?

I write more items to listBox, and i can add linklabels at delete links.
Example:
1. book ............. <a>delete</a> (this is linklabel id book is 1)
2. book ............. <a>delete</a> (id this book is 2)
...
...

Thanks for whatever answer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.