您的位置:首页 > 编程语言 > C#

c#.net 文本编辑控件——RichTextBox中插入图片

2009-08-28 16:56 399 查看
private void InsertImage()
{
OpenFileDialog openImageDlg = new OpenFileDialog();
openImageDlg.Filter = "所有图片(*.bmp,*.gif,*.jpg)|*.bmp;*.gif;*jpg";
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 (curRichTextBox.CanPaste(dataFormat))
curRichTextBox.Paste(dataFormat);
}
catch (Exception exc)
{
MessageBox.Show("图片插入失败。" + exc.Message, "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐