Text on top/outside of picturebox

Joined
Jul 6, 2023
Messages
3
Reaction score
0
Hey all I am trying to figure out why my text is not showing past my picturebox:

2025-03-18 14_52_28-AgIji78J.png (208×203).png


The code I am using is this:

C#:
Image NewImage = Image.FromFile(imgSaveResized + newImgExt);
NewImage = NewImage.GetThumbnailImage((int)(NewImage.Width * 0.5), (int)(NewImage.Height * 0.5), null, IntPtr.Zero);
PictureBox P = new PictureBox();

P.SizeMode = PictureBoxSizeMode.AutoSize;
P.Image = NewImage;
P.Margin = new Padding(5, 5, 55, 35);   
P.Paint += new PaintEventHandler((sender, e) =>
{
    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

    string text = "Text";

    Font myFont = new Font("Arial", 18, FontStyle.Italic, GraphicsUnit.Pixel);
    SizeF textSize = e.Graphics.MeasureString(text, Font);
    PointF locationToDraw = new PointF();
    locationToDraw.X = (P.Width / 2) - (textSize.Width / 2);
    locationToDraw.Y = (P.Height / 2) - (textSize.Height / 2)+85;

    e.Graphics.DrawString(text, myFont, Brushes.Red, locationToDraw);
});

flowLayoutStations.Controls.Add(P);

I know its because its being added to the picturebox (P) but i am not sure how to go about setting the picturebox and the behind so that the text can be dominant on top f it?
 

Attachments

  • 2025-03-18 11_12_10-Form1.png
    2025-03-18 11_12_10-Form1.png
    48 KB · Views: 3

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,305
Messages
2,571,569
Members
48,373
Latest member
DevinNorri
Top