C#中,打开openFileDialog后,如何将选中的图片显示在richtextBox中
3个回答
展开全部
图片需要转换一下才会显示在richtextBox中,但是不支持Gif动态图片(我试过的)
//插入图片
OpenFileDialog op1 = new OpenFileDialog();
if (op1.ShowDialog() == DialogResult.OK)
{
//Bitmap bmp = new Bitmap(op1.FileName);
Image img = Image.FromFile(op1.FileName);
Clipboard.SetDataObject(img, true);
if (richTextBox1.CanPaste(DataFormats.GetFormat(DataFormats.Dib)))
{
richTextBox1.Paste();
}
}
//插入图片
OpenFileDialog op1 = new OpenFileDialog();
if (op1.ShowDialog() == DialogResult.OK)
{
//Bitmap bmp = new Bitmap(op1.FileName);
Image img = Image.FromFile(op1.FileName);
Clipboard.SetDataObject(img, true);
if (richTextBox1.CanPaste(DataFormats.GetFormat(DataFormats.Dib)))
{
richTextBox1.Paste();
}
}
展开全部
private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg";
this.openFileDialog1.ShowDialog();
if (this.openFileDialog1.FileName != "")
{
Image img = Bitmap.FromFile(this.openFileDialog1.FileName);
Graphics g = richTextBox1.CreateGraphics();
g.DrawImage(img, 0, 0);
}
}
{
this.openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg";
this.openFileDialog1.ShowDialog();
if (this.openFileDialog1.FileName != "")
{
Image img = Bitmap.FromFile(this.openFileDialog1.FileName);
Graphics g = richTextBox1.CreateGraphics();
g.DrawImage(img, 0, 0);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我用代码给你简单的事例一下吧:
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "gif文件,jpg文件,bmp文件|*.gif;*.jpg;*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bit = new Bitmap(open.FileName);
Insert(bit);
}
}
void Insert(Bitmap b)
{
Clipboard.SetDataObject(b);
DataFormats.Format bitFormat = DataFormats.GetFormat(DataFormats.Bitmap);
if (richTextBox1.CanPaste(bitFormat))
{
richTextBox1.Paste(bitFormat);
}
}
}
}
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "gif文件,jpg文件,bmp文件|*.gif;*.jpg;*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bit = new Bitmap(open.FileName);
Insert(bit);
}
}
void Insert(Bitmap b)
{
Clipboard.SetDataObject(b);
DataFormats.Format bitFormat = DataFormats.GetFormat(DataFormats.Bitmap);
if (richTextBox1.CanPaste(bitFormat))
{
richTextBox1.Paste(bitFormat);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询