I need to stretch various sized bitmaps to fill a PictureBox.
PictureBoxSizeMode.StretchImage sort of does what I need but can’t think of a way to properly add text or lines to the image using this method. The image below is a 5×5 pixel Bitmap stretched to a 380×150 PictureBox.

pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox.Image = bmp;
I tried adapting this example and this example this way
using (var bmp2 = new Bitmap(pictureBox.Width, pictureBox.Height))
using (var g = Graphics.FromImage(bmp2))
{
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(bmp, new Rectangle(Point.Empty, bmp2.Size));
pictureBox.Image = bmp2;
}
but get this

What am I missing?
It appears you’re throwing away the bitmap (
bmp2) you’d like to see in your picture box! Theusingblock from the example you posted is used because the code no longer needs theBitmapobject after the code returns. In your example you need the Bitmap to hang around, hence nousing-block on thebmp2variable.The following should work: