Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Set your form's KeyPreview property to True. Then add this line of code to the top of your CS file:</p> <pre><code>using System.IO; </code></pre> <p>Next, inside the scope of your form, add these two lines:</p> <pre><code>private FileInfo[] _files; private int _currentFile; </code></pre> <p>In your form's Load event, put this code:</p> <pre><code>DirectoryInfo dirinfo = new DirectoryInfo( Path.Combine(Application.StartupPath, "images")); _files = dirinfo.GetFiles(); _currentFile = 0; Bitmap bmp = (Bitmap)Bitmap.FromFile(_files[_currentFile].FullName); pictureBox1.Image = bmp; </code></pre> <p>Finally, in your form's KeyDown event, put this code:</p> <pre><code>if (e.KeyCode == Keys.Down) { _currentFile--; if (_currentFile &lt; 0) { _currentFile = _files.Length - 1; } } else if (e.KeyCode == Keys.Up) { _currentFile++; if (_currentFile &gt;= _files.Length) { _currentFile = 0; } } Bitmap bmp = (Bitmap)Bitmap.FromFile(_files[_currentFile].FullName); if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = bmp; </code></pre> <p>This code assumes that you have a PictureBox on your form named "pictureBox1", and it assumes that you have a folder named "\images" in your application folder that contains the image files you wish to display.</p> <p>As o.k.w. mentioned in a comment, you may want to enhance this code by resizing the PictureBox to fit the dimensions of the image file. You can do that by setting the SizeMode property of your PictureBox to AutoSize (or set it to CenterImage, if you wish to keep the overall image centered on your form).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload