I wonder, how to make a single letter clickable on a RichTextBox
or Label
(doesn't matter). Previously I used buttons on a text, but it looks ugly. Is there any other way?
For example: letter B
in word TextBox
shoud be clickable
Some text in Text B ox.
You can add link controls to your RichTextBox like this:
richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 16);
richTextBox1.Text = "Text";
var clickablePart = new LinkLabel();
clickablePart.Text = "B";
clickablePart.AutoSize = true;
clickablePart.Font = richTextBox1.Font;
clickablePart.LinkClicked += clickablePart_LinkClicked;
clickablePart.Location = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength);
richTextBox1.Controls.Add(clickablePart);
richTextBox1.AppendText(" ox");
private void clickablePart_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("Clicked");
}
Result:
You might need to play around the size to get it to fit exactly. But I think that would not be a problem for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.