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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
nishant ranjanPosted Jul 26, 2011, 8:29 AM
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.
nishant ranjanPosted Jul 26, 2011, 8:15 AM
Zoran HorvatPosted Jul 25, 2011, 7:28 AM
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 ranjanPosted Jul 25, 2011, 7:06 AM
Zoran HorvatPosted Jul 25, 2011, 6:55 AM
Zoran
nishant ranjanPosted Jul 25, 2011, 6:51 AM
Zoran HorvatPosted Jul 25, 2011, 6:39 AM
Zoran
nishant ranjanPosted Jul 25, 2011, 6:37 AM
Zoran HorvatPosted Jul 25, 2011, 5:04 AM
textbox1.Location = image.Location;
textbox2.Location = new Point(image.Right - textbox2.Width, image.Bottom - textbox2.Height);
textbox1.BringToFront();
textbox2.BringToFront();
Zoran