RichTextBox中插入图片的方法

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.");
 }
}
 

你可能感兴趣的:(object,String)