RTF格式规范规定图片信息都是以pict控制字码开头。当点击RichTextBox时,我们可以通过判断选中的Rtf字符串是否包含pict来检测是否点击在图片上。请参考以下代码:
代码:
this.richTextBox1.MouseClick += new MouseEventHandler(richTextBox1_MouseClick);
void richTextBox1_MouseClick(object sender, MouseEventArgs e)
{
if (this.richTextBox1.SelectedRtf.IndexOf(@"pict") != -1 &&
this.richTextBox1.SelectionType == RichTextBoxSelectionTypes.Object)
{
MessageBox.Show("Image has been clicked!");
}
}