i have two textbox
textbox1 and textbox2
one image
i want to show textbox1 text on left top of image
and textbox2 text on right bottom of image
how can i do this.
or simply how can i show a label over image.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 1:04 AM EDT
textbox1.Location = image.Location;
textbox2.Location = new Point(image.Right - textbox2.Width, image.Bottom - textbox2.Height);
textbox1.BringToFront();
textbox2.BringToFront();
Zoran
nishant ranjanRank #4,961 · 317 reputationPosted Jul 25, 2011, 2:37 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 2:39 AM EDT
Zoran
nishant ranjanRank #4,961 · 317 reputationPosted Jul 25, 2011, 2:51 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 2:55 AM EDT
Zoran
nishant ranjanRank #4,961 · 317 reputationPosted Jul 25, 2011, 3:06 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 3:28 AM EDT
If you have textbox1 and textbox2 as TextBox controls, and image which is PictureBox control, then you can set the image of the picture box like this:
// Here I'm creating Image img, but you will actually load it as you normally do
Image img = new Bitmap(100, 100);
using (Graphics gr = Graphics.FromImage(img))
{
SolidBrush brush = new SolidBrush(Color.DarkRed);
gr.FillRectangle(brush, new Rectangle(new Point(0, 0), img.Size));
}
image.Tag = img; // Set both Tag and Image of the picture box - Tag will contain the original image
image.Image = img;
// handling TextChanged event in textbox1 and textbox2 with same method
textbox1.TextChanged += new EventHandler(TextBoxTextChanged);
textbox2.TextChanged += new EventHandler(TextBoxTextChanged);
Now TextBoxTextChanged method is crucial - it will modify the picture shown in picture box:
void TextBoxTextChanged(object sender, EventArgs e)
{
Image img = (Image)image.Tag;
img = (Image)img.Clone();
using (Graphics gr = Graphics.FromImage(img))
{
SizeF t1Size = gr.MeasureString(textbox1.Text, this.Font);
SizeF t2Size = gr.MeasureString(textbox2.Text, this.Font);
Brush brush = new SolidBrush(Color.Yellow);
gr.DrawString(textbox1.Text, this.Font, brush, new PointF(0, 0));
gr.DrawString(textbox2.Text, this.Font, brush, new PointF(img.Width - t2Size.Width, img.Height - t2Size.Height));
}
image.Image = img;
}
This method picks up the original image from the Tag property, clones it (important, because you can't modify original image multiple times) and then draws two strings over it. Once done, new Image value is set in the picture box. Result is that picture box changes its appearance with every keystroke on the text box.
Zoran
nishant ranjanRank #4,961 · 317 reputationPosted Jul 26, 2011, 4:15 AM EDT
nishant ranjanRank #4,961 · 317 reputationPosted Jul 26, 2011, 4:29 AM EDT
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.DrawString(sendtotxt.Text, new Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 10));
graphicImage.DrawString(sendfromtxt.Text, new Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(400, 600));
Response.ContentType = "image/jpeg";
bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
graphicImage.Dispose();
bitMapImage.Dispose();
this is working for me but the output is in new window. but i want that the image should show in a panel.