private void InsertImage()
{
OpenFileDialog openImageDlg = new OpenFileDialog();
openImageDlg.Filter = "所有图片(*.bmp,*.gif,*.jpg)|*.bmp;*.gif;*jpg";//格式过滤s
openImageDlg.Title = "选择图片";
Bitmap bmp;
if (openImageDlg.ShowDialog() == DialogResult.OK)
{
string fileName = openImageDlg.FileName;
if (null == fileName || fileName.Trim().Length == 0)
return;
try
{
bmp = new Bitmap(fileName);
Clipboard.SetDataObject(bmp);//将数据置于系统剪贴板中
DataFormats.Format dataFormat = DataFormats.GetFormat(DataFormats.Bitmap);//格式
if (richTextBox1.CanPaste(dataFormat))
richTextBox1.Paste(dataFormat);
}
catch (Exception exc)
{
MessageBox.Show("图片插入失败。" + exc.Message, "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}