Display Image Alternative

For the project I'm working on, a timer should be shown on the form. If I remember correctly in VB, the text could be displayed in the image window, but I cannot find a way to do this in C #. The label will work if there is a way to prevent window resizing. Thank you

+3
source share
2 answers

A shortcut is likely to be the easiest option. I'm not sure why you will need to prevent image resizing (which is also easy to do).

If you are worried about resizing your photo box and your shortcut is no longer centered or incorrect, you can simply put the code in a resize event that dynamically updates the size and location of the label and its font based on the current size of the image window.

However, if you are configured not to use shortcuts, you can always subscribe to your icon for the Paint event, and then use e.Graphics to simply draw text whenever the image is repainted.

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    using (Font myFont = new Font("Microsoft Sans Serif", 10))
    {
        e.Graphics.DrawString("This time is...Hammertime", myFont, Brushes.Black, new Point(0,0));
    }
}

However, you will also have to redraw this for each iteration of your timer.

As I said, a shortcut would be a better option than this. Calling e.Graphics will not give you any real advantages over Label, but it will create more things you can worry about.

+2
source

TextBox, , ; ReadOnly true.

+1

Source: https://habr.com/ru/post/1791752/


All Articles