RichTextBox中插入图片的方法

来源:互联网 发布:什么是数据漫游 编辑:程序博客网 时间:2024/04/30 03:56
1.      通过剪切板来实现。
public void InsertImage() {
 string lstrFile = fileDialog.FileName;
 Bitmap myBitmap = new Bitmap(lstrFile);
 // Copy the bitmap to the clipboard.
 Clipboard.SetDataObject(myBitmap);
 // Get the format for the object type.
 DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
 // After verifying that the data can be pasted, paste
 if(myRichTextBox.CanPaste(myFormat)) {
    myRichTextBox.Paste(myFormat);
 }
 else {
    MessageBox.Show("The data format that you attempted site" +
      " is not supportedby this control.");
 }
}
 
原创粉丝点击