Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow
in Form1 i add pictureBox1 it contains an image =Tulips.jpg , i want to draw a string at location 10,20
but i could not
C#
using System.Drawing.Imaging;
//...
//...
        Image MyImage;
        //....
        //.....
        private void Form1_Load(object sender, EventArgs e)
        {
            MyImage = Image.FromFile("Tulips.jpg");
            pictureBox1.Image = MyImage;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics dc = Graphics.FromImage(pictureBox1.Image);//MyImage);
dc.DrawString("hellow", new Font("Arial", 12), new SolidBrush(Color.Black), 10, 20);//<----
            dc.Dispose();
        }
Posted
Comments
[no name] 17-Aug-14 7:46am    
http://stackoverflow.com/questions/849359/how-to-draw-text-on-picturebox

The code you show should draw text on an image - but it won't show in the display, or be reflected in the image file.
In order to see the image with the text, add
C#
pictureBox1.Invalidate();
after your draw code.

In order to change the image file, you will have to save the image to a new file.

BTW: you should also dispose the Font and Brush objects that you create.
 
Share this answer
 
Hi
Use
C#
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
//your code to draw string
}
 
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