RichTextBoxでリンクのaltクリックを検出する方法
-
07-07-2019 - |
質問
WinFormにURL:sのRichTextBoxがあります。 それらはクリックできますが、ユーザーが右クリックしたかどうかを検出したいです。
解決
これがあなたが探しているものだと思います。 MouseDownEventで、最初に右クリックを処理していることを確認します。次に、クリックされた位置を把握し、テキストに戻ります。
private void DoMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
RichTextBox rtb = (RichTextBox)sender;
int charIndex = rtb.GetCharIndexFromPosition(new Point(e.X, e.Y));
int lineIndex = rtb.GetLineFromCharIndex(charIndex);
string clickedText = rtb.Lines[lineIndex];
// now check if the text was indeed a link
Regex re = new Regex("http://(www\\.)?([^\\.]+)\\.([^\\.]+)");
bool isLink = re.IsMatch(s);
}
}
所属していません StackOverflow