winForm中,如何在richtext中插入bmp、jpg、gif等图片? 在线等答案,急急急……
展开全部
用代码简单的事例一下:
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);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询