富文本粘贴图片

        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);

                }

            }

        }

你可能感兴趣的:(图片)