Reputation: 89
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
Upvotes: 3
Views: 16368
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);
The image will float above the text, cover it and get in the way :-(
What you can't do is
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..RichTextBox
!Upvotes: 4