Display JPG in Full Screen Mode

  • Thread starter Thread starter zacks
  • Start date Start date
Z

zacks

I know how to use the image class to display a JPG image in a
PictureBox. I would like to be able to display the image in full
screen mode. I have searched for code examples but cannot locate any.
Any help would be appreciated.
 
I know how to use the image class to display a JPG image in a
PictureBox. I would like to be able to display the image in full
screen mode. I have searched for code examples but cannot locate any.
Any help would be appreciated.

It's not glamorous, but a simple way is to perhaps put the picture
box on a form, size it to be about the size of the form, set the
border style to none, anchor the picturebox to the top, left, bottom
and right and depending on your usage requirement, set the picture box
to either autosize or stretch
 
It's not glamorous, but a simple way is to perhaps put the picture
box on a form, size it to be about the size of the form, set the
border style to none, anchor the picturebox to the top, left, bottom
and right and depending on your usage requirement, set the picture box
to either autosize or stretch

I had thought that there must be some built in .NET method that would
do this but apparently there is not. But as you suggest, it can be
done "manually". Here's how.

Create a form to display the full screen image. Size in design mode is
irrelevant. But set these properties:

BackColor - To what ever color you prefer displayed in areas not
covered by the image itself. I prefer Black.
FormBorderStyle - None
StartPosition - Manual
Top - 0
Left - 0
WindowState - Maximized (strange that this is required. if you don't
set it the form doesn't go completely full screen)

Add a PictureBox control to the form. Set these properties:

Location - 0, 0
SizeMode - Zoom (to ensure the image is displayed in the proper aspect
ratio)
Make the size equivalent to the size of the form's content area.
Set the Anchor property to Top, Bottom, Left, Right.

The code to display the image:

Instantiate the form.
Set the Width property to Screen.PrimaryScreen.WorkingArea.Width
Set the Height property to Screen.PrimaryScreen.WorkingArea.Height
Set the PictureBox.Image property to an instance of the Image class
that has had the JPG loaded into it.
Show the form with the ShowDialog method.

Be sure to add an OnClick event handler for the PictureBox to close
the form when you click on it. I also added a form KeyDown event
handler so I could also close the form by hitting ESC. There's no way
to close the form if neither of these are done.
 
I had thought that there must be some built in .NET method that would
do this but apparently there is not. But as you suggest, it can be
done "manually". Here's how.

Create a form to display the full screen image. Size in design mode is
irrelevant. But set these properties:

BackColor - To what ever color you prefer displayed in areas not
covered by the image itself. I prefer Black.
FormBorderStyle - None
StartPosition - Manual
Top - 0
Left - 0
WindowState - Maximized (strange that this is required. if you don't
set it the form doesn't go completely full screen)

Add a PictureBox control to the form. Set these properties:

Location - 0, 0
SizeMode - Zoom (to ensure the image is displayed in the proper aspect
ratio)
Make the size equivalent to the size of the form's content area.
Set the Anchor property to Top, Bottom, Left, Right.

The code to display the image:

Instantiate the form.
Set the Width property to Screen.PrimaryScreen.WorkingArea.Width
Set the Height property to Screen.PrimaryScreen.WorkingArea.Height
Set the PictureBox.Image property to an instance of the Image class
that has had the JPG loaded into it.
Show the form with the ShowDialog method.

Be sure to add an OnClick event handler for the PictureBox to close
the form when you click on it. I also added a form KeyDown event
handler so I could also close the form by hitting ESC. There's no way
to close the form if neither of these are done.

Simple solutions to simple problems :)
 

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

Back
Top