c# 点击按选择图片然后展示在richTextBox中
2021-07-05 07:16
标签:pdo ring str string focus director show 失败 filter OpenFileDialog o = new OpenFileDialog(); DataFormats.Format dataFormat = DataFormats.GetFormat(DataFormats.Bitmap); } } c# 点击按选择图片然后展示在richTextBox中 标签:pdo ring str string focus director show 失败 filter 原文地址:https://www.cnblogs.com/jakejian/p/9833680.html
o.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
o.Title = "请选择图片";
o.Filter = "jpeg|*.jpeg|jpg|*.jpg|png|*.png|gif|*.gif";
if (o.ShowDialog() == DialogResult.OK)
{
picPath = o.FileName;//picPath在前面定义为string
try
{
Image bmp = Image.FromFile(picPath);//picPath为图片路径
Clipboard.SetDataObject(bmp);
if (richText.CanPaste(dataFormat))//图片展示在一个叫richText的richTextBox中
{
richText.Paste(dataFormat);
}
catch (Exception exc)
{
MessageBox.Show("图片插入失败。" + exc.Message, "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
richText.Focus();
}
}
下一篇:【WPF】三维模型中的“照相机”
文章标题:c# 点击按选择图片然后展示在richTextBox中
文章链接:http://soscw.com/index.php/essay/102003.html