The Picture Frame source code can be downloaded from: 
As promised here is the source code for my Picture Frame application.   For a desciption of how I wrote this see Why this C/C++ programmer struggled with writing a simple C# application
This application runs full screen, although I haven’t spent any time or thought into hiding the task bar since I run it without the Explorer shell. It then displays JPEG or BMP files found in the root folder of either \Storage Card or \Hard Disk. It displays the pictures one at a time for 10 seconds.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.IO;
 
namespace PictureFrame
{
    public delegate void DelegateChangeBMP(Bitmap BMP);
 
    public partial class Form1 : Form
    {
        public DelegateChangeBMP m_DelegateChangeBMP;
        Thread m_PictureUpdateThread;
The constructure for Form1 sets up the delagate function for changing the PictureBox image and starts the PictureUpdate thread.
 
        public Form1()
        {
            InitializeComponent();
 
            m_DelegateChangeBMP = new DelegateChangeBMP( this.ChangeBMP );
            m_PictureUpdateThread = new Thread(new ThreadStart(this.StartPictureUpdate));
            m_PictureUpdateThread.Start();
        }
StartPictureUpdate creates a runs as a new thread, and runs the picture update.
        private void StartPictureUpdate()
        {
            CPictureUpdate PictureUpdate;
 
            PictureUpdate = new CPictureUpdate(this);
            PictureUpdate.Run();
        }
ChangeBMP assigns the new Bitmap to the PictureBox image and invalidates the PictureBox so that it redraws.
        public void ChangeBMP(Bitmap BMP)
        {
            if( pictureBox1.Image != null )
                pictureBox1.Image.Dispose();
            pictureBox1.Image = BMP;
            pictureBox1.Visible = true;
            pictureBox1.Invalidate();
        }
 
    }
 
    public class CPictureUpdate
    {
        // Reference to main form used to make syncronous user interface calls:
        Form1 m_form;
CPictureUpdate is passed a reference to the main form. CPictureUpdate.Run() loops through an array of search directories. For each directory, it loops through an array of file types to find the picture files to display. Each picture file is passed to the main form by Invoking the delegate function.
 
        public CPictureUpdate(Form1 form)
        {
            m_form = form;
        }
 
        // Function runs in worker thread and emulates long process.
        public void Run()
        {
            string[] FileType = {"*.jpeg", "*.jpg", "*.bmp"};
            string[] SearchDir = {"\\Storage Card", "\\Hard Disk"};
 

 

 

         while (true)
        
{
              
foreach( string Dir in SearchDir )
               {
                   
DirectoryInfo DI = new DirectoryInfo(Dir);
                   
if (DI.Exists)
                    {
                        
foreach (string Type in FileType)
                         {
                               
foreach (FileInfo fi in DI.GetFiles(Type))
                               {
                                    
m_form.Invoke(m_form.m_DelegateChangeBMP,
                                    
new Bitmap(fi.FullName));                                     // Let the BMP display for 10 seconds
                                   
Thread.Sleep(10000);
                               }
                         }
                   }
            }
       }
    }
}
 
The project is very simple, I created a smart device application project and dropped a PictureBox on the form.   Then I set the properties of the PictureBox SizeImage to StrechImage and Dock to Fill.  Then I set the form property WindowState to Maximize.
Copyright © 2008 – Bruce Eitman
All Rights Reserved