문제

URL : s와의 Winform에 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);
        }            
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top