JumboJey
JumboJey

Reputation: 89

Image inside a TextBox Control C#

I have a Windows Form with a TextBox and I would like to send some text together with an image inside to a Inbox list of messages. For the preview of the image, I used javascript. Selection of the image is done with FileUpload. Like this preview function. I want to upload this image to the TextBox and save it in my database. Is there a way to include this image. I have only seen RichTextBox. What about drag and drop???

This TextBox is with a button included

This is what I want. I can see that here is the same The result

Upvotes: 3

Views: 16368

Answers (1)

TaW
TaW

Reputation: 54433

What you can do is add a Control to the TextBox, which shows an Image.

Label imgLabel = new Label();
imgLabel.Image = Image.FromFile(somefile);
imgLabel.AutoSize = false;
imgLabel.Size = imgLabel.Image.Size;
imgLabel.ImageAlign = ContentAlignment.MiddleCenter;
imgLabel.Text = "";
imgLabel.BackColor = Color.Transparent;
imgLabel.Parent = textBox1;
// pick a location where it won't get in the way too much
imgLabel.Location = new Point(textBox1.ClientSize.Width - imgLabel.Image.Width, 0);

enter image description here

The image will float above the text, cover it and get in the way :-(

What you can't do is

  • Put that control behind the TextBox's text. I don't know of any Control that can do that in Winforms; both TextBox and RichTextBox do not support transparency, alas..
  • Embed the image in the text and have it flow around it. For this you need to use a RichTextBox!

Upvotes: 4

Related Questions