Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I wonder if anyone know how to insert image on the textbox?
Sincerely Yours
Posted
Comments
Uday P.Singh 15-Oct-11 13:48pm    
window or web?
BillWoodruff 15-Oct-11 21:32pm    
Please clarify: my guess is that you want the ability to insert images into the text: i.e., 'in-line.'

1. You want a TextBox in your WinForms app that at run-time the user can type into, and edit text ?

2. You want to insert images into the text in the TextBox, or are you talking about a Background Image only ?

3. If you are inserting images into the text, does this happen at both design-time, and, the user can also insert at run-time ?

My first thought was that you should switch to a RichTextBox, for inserting images in-line into the text, and I see TheAnil has already replied with a solution for that.

thanks, Bill
RaviRanjanKr 16-Oct-11 16:36pm    
hey! Bill that could be an answer. whatever its a Nice suggestion.

this may help you insert image into rich text

C#
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.");
            }
 
        }
 
Share this answer
 
v2
Owner-drawing a Windows.Forms TextBox[^] could help (although it uses some native code).
 
Share this answer
 
if you need for web application you can try using css
XML
<asp:textbox ID="txtImage" runat="server"  style="background-image:url(imagepath)"></asp:textbox>
 
Share this answer
 
Dear Buddy:

I want to have a background image for my textbox and then add text to it in C# windows form application to make it more attractive.

I also want these features for a textBox. I have tried above code but I didnt get appropariate result. Would you please guide me to deal with this challenge?



Yours.
 
Share this answer
 
Dear Buddies:

I want to have a fixed background image for my textbox in my windows application program. I want to make the textbox more attractive and I do not want to add in-line image in the text box.

Yours
 
Share this answer
 
adds 16x16 px to the textbox

C#
PictureBox pic = new PictureBox();
pic.Width = 16;
pic.Height = 16;
pic.BackgroundImage = WindowsFormsApplication2.Properties.Resources.qq;
textBox1.Controls.Add(pic);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900