如何将图像添加到文本框中 [英] How to add image into textbox

查看:85
本文介绍了如何将图像添加到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道如何在文本框中插入图片?

此致

解决方案

这可能有助于您将图片插入富文本



  public   void  InsertImage( string  pic)
{
// string lstrFile = fileDialog.FileName;
string lstrFile = pic;
Bitmap myBitmap = new 位图(lstrFile);
// 将位图复制到剪贴板。
Clipboard.SetDataObject(myBitmap) );
// 获取对象类型的格式。
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
// 验证数据可以粘贴后,粘贴
if (richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste(myFormat);
}
else
{
MessageBox.Show( 您尝试网站的数据格式 +
);
}

}


所有者绘制Windows.Forms TextBox [ ^ ]可能会有所帮助(虽然它使用了一些本机代码)。


如果您需要Web应用程序,可以尝试使用CSS

 <   asp:textbox     ID   =   txtImage    runat   =  server      style   =  background-image:url(imagepath) > ;  <   / asp:textbox  > ;  


I wonder if anyone know how to insert image on the textbox?
Sincerely Yours

解决方案

this may help you insert image into rich text

public void InsertImage(string pic)  
        {
            //string lstrFile = fileDialog.FileName;
            string lstrFile = pic;
            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(richTextBox1.CanPaste(myFormat)) 
            {
                richTextBox1.Paste(myFormat);
            }
            else 
            {
                MessageBox.Show("The data format that you attempted site" + 
                    " is not supportedby this control.");
            }
 
        }


Owner-drawing a Windows.Forms TextBox[^] could help (although it uses some native code).


if you need for web application you can try using css

<asp:textbox ID="txtImage" runat="server"  style="background-image:url(imagepath)"></asp:textbox>


这篇关于如何将图像添加到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆