How to make Slideshow in C#

Introduction:

Now it is possible to show slide show on the desktop of your favorite images for Windows XP also as in Windows Vista. This application is able to do slideshow of images. This application saved all modification whatever you did in the last.

Step1:

Add a form in your application and set it's WindowState property Maximize by using its Property.

Also apply its FormBorderStyle none.

Step 2:

Then add 4 controls namely PictureBox, FolderBrowserDialoge, Timer and ContexMenuStrip.

In PictureBox you can set any image. Here I have set mine.

Now all the required controls have been added to the application.

Step 3:

Now in 3rd step we have to set a menu as shown in the pictures below in the ContexMenuStrip so the user can access your slideshow application easily after it completed.

slide.gif 


        private void browseToolStripMenuItem_Click(object sender, EventArgs e)

        {
            if (PicFolderBrowser.ShowDialog() == DialogResult.OK)
            {

                /*
*  path file function works to create directory and text file in c drive named SlideShow         
*  and path.txt. path.txt file saved your browsed folder path for picture slideshow.
                  */

                pathFile();
                /*

*   systemFiles() function generate text files which is usefull to save your last  
*   modification.
                  */

                systemFiles();

 
                TimerSlideShow.Start();

 
                /*

*   intervalUnchecked() function used to remove all checked sign releated to menu option.
                  */

                intervalUnchecked();

 
                TimerSlideShow.Interval = 2000;
                toolStripMenuItem27.Checked = true;

 
                /*

*   slideShowEnable() function enable the two submenu which is defined in the Slide Show *   Menu.
                  */

                slideShowEnable();              
            }
        }   
           
  int init=0,slideshow=0,imageJ;
  float imageI;
        string path;

        private void TimerSlideShow_Tick(object sender, EventArgs e)
        {
            try
            {

                /*

*  slideShowMethod() is the heart Part of the Application. Because of this function we *  *  can view the slideshow.

                  */
 
                slideShowMethod();            
            }
            catch (Exception)
            {
                TimerSlideShow.Stop();

MessageBox
.Show("Please select proper path....", "Path Error...", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        String []files;
        private void slideShowMethod()
        {
            files = Directory.GetFiles(@path, "*.jpg");
            if (files.Length == 0)
            {
                TimerSlideShow.Stop();
MessageBox.Show("Folder Does not contain any Picture", "No picture Found",MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (slideshow == 0)
            {
                if (init < files.Length)
                {
                    pbox.Load(files[init]);
                    init++;
                }
                else
                {
                    init = 0;
                }
            }
            else if (slideshow == 1)
            {
                imageI = Microsoft.VisualBasic.VBMath.Rnd();
                imageJ = Convert.ToInt32(imageI * files.Length);
                if (imageJ < files.Length)
                {
                    pbox.Load(files[imageJ]);
                }
            }
        }

        private void pathFile()
        {
            string dirname = @"C:\Program Files\SlideShow";
            Directory.CreateDirectory(dirname);

            string filename = @"C:\Program Files\SlideShow\path.txt";
            FileStream filePath = File.Create(filename);

            StreamWriter pathwrite = new StreamWriter(filePath);
            pathwrite.Write(PicFolderBrowser.SelectedPath);
            pathwrite.Close();

            StreamReader pathRead = new StreamReader(filename);
            path = pathRead.ReadLine();
            pathRead.Close();
            filePath.Close();                  
        }

        private void systemFiles()
        {
            FileStream trans = File.Create(@"C:\Program Files\SlideShow\transparency.txt");
            StreamWriter transWrite = new StreamWriter(trans);
            transWrite.Write("0");
            transWrite.Close();

            FileStream bord = File.Create(@"C:\Program Files\SlideShow\border.txt");
            StreamWriter bordWrite = new StreamWriter(bord);
            bordWrite.Write("Fixed3D");
            bordWrite.Close();
 
            FileStream inter = File.Create(@"C:\Program Files\SlideShow\interval.txt");
            StreamWriter interWrite = new StreamWriter(inter);
            interWrite.Write("2sec");
            interWrite.Close();

 
            FileStream posit = File.Create(@"C:\Program Files\SlideShow\position.txt");
            StreamWriter positWrite = new StreamWriter(posit);
            positWrite.Write("CenterRight");
            positWrite.Close();

            FileStream slide = File.Create(@"C:\Program Files\SlideShow\slideShowType.txt");
            StreamWriter slidWrite = new StreamWriter(slide);
            slidWrite.Write("Sequentially");
            slidWrite.Close();

 
            FileStream sizeF = File.Create(@"C:\Program Files\SlideShow\size.txt");
            StreamWriter sizWrite = new StreamWriter(sizeF);
            sizWrite.Write("Normal");
            sizWrite.Close();
        }

 
  
        private void slideShowEnable()
        {
            rendomlyToolStripMenuItem.Enabled = true;
            sequantialyToolStripMenuItem.Enabled = true;
        }
        private void slideShowDisable()
        {
            rendomlyToolStripMenuItem.Enabled =false;
            sequantialyToolStripMenuItem.Enabled = false;
        }

        private void secondToolStripMenuItem5_Click(object sender, EventArgs e)
        {

         /** Working started of the submenu SlideShowTiming

 *This is the first option named 1 second of the submenu named SlideShowTiming of the menu 
* Visualization.
     */

                 
            TimerSlideShow.Interval = 1000;

 
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();

 
            secondToolStripMenuItem5.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("1sec");
            intervalWrite.Close();
        }
        private void toolStripMenuItem27_Click(object sender, EventArgs e)
        {  

 
            TimerSlideShow.Interval = 2000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            toolStripMenuItem27.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("2sec");
            intervalWrite.Close();
        }
        private void secondToolStripMenuItem6_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 3000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            secondToolStripMenuItem6.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("3sec");
            intervalWrite.Close();
        }

 
        private void secondToolStripMenuItem7_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 5000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            secondToolStripMenuItem7.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("5sec");
            intervalWrite.Close();
        }

 
        private void secondToolStripMenuItem8_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 10000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            secondToolStripMenuItem8.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("10sec");
            intervalWrite.Close();
        }

 
        private void secondToolStripMenuItem9_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 30000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            secondToolStripMenuItem9.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("30sec");
            intervalWrite.Close();
        }

 
        private void minuteToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 60000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            minuteToolStripMenuItem1.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("1min");
            intervalWrite.Close();
        }

 
        private void minuteToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 180000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            minuteToolStripMenuItem2.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("3min");
            intervalWrite.Close();
        }

 
        private void minuteToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            TimerSlideShow.Interval = 300000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            minuteToolStripMenuItem3.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("5min");
            intervalWrite.Close();
        }

        private void minuteToolStripMenuItem4_Click(object sender, EventArgs e)
        {
     /*

* Working complted of the submenu SlideShowTiming
*This is the last option named 10 minute of the submenu named SlideShowTiming of the menu 
* Visualization.
     */

 
            TimerSlideShow.Interval = 600000;
            TimerSlideShow.Start();
            intervalUnchecked();
            slideShowEnable();
            minuteToolStripMenuItem4.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("10min");
            intervalWrite.Close();
        }
        private void intervalUnchecked()
        {
            secondToolStripMenuItem5.Checked = false; toolStripMenuItem27.Checked = false;
            secondToolStripMenuItem6.Checked = false; secondToolStripMenuItem7.Checked = false;
            secondToolStripMenuItem8.Checked = false; secondToolStripMenuItem9.Checked = false;
            minuteToolStripMenuItem1.Checked = false; minuteToolStripMenuItem2.Checked = false;
            minuteToolStripMenuItem3.Checked = false; minuteToolStripMenuItem4.Checked = false;
            staticViewToolStripMenuItem1.Checked = false;
          }

 
        private void staticViewToolStripMenuItem1_Click(object sender, EventArgs e)
        {
          /*

            * By using this menu we can stop the slideshow at the current picture.
     */

     
            TimerSlideShow.Stop();          
            slideShowDisable();
            intervalUnchecked();
            staticViewToolStripMenuItem1.Checked = true;
            StreamWriter intervalWrite = new StreamWriter(@"C:\Program Files\SlideShow\interval.txt");
            intervalWrite.Write("static");
            intervalWrite.Close();
        }

        private void toolStripMenuItem12_Click(object sender, EventArgs e)
        {
            /*

* This is the first option of the Transparency menu of the Visualization. We can set the set     * the 0% opacity by using this option
     */

 
            this.Opacity = 1;
            opacityUncheked();
            toolStripMenuItem12.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("0");
            transparencyWrite.Close();
        }

        private void toolStripMenuItem13_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.9;
            opacityUncheked();
            toolStripMenuItem13.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("10");
            transparencyWrite.Close();
        }

 
        private void toolStripMenuItem14_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.8;
            opacityUncheked();
            toolStripMenuItem14.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("20");
            transparencyWrite.Close();
        }

 
        private void toolStripMenuItem15_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.7;
            opacityUncheked();
            toolStripMenuItem15.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("30");
            transparencyWrite.Close();
        }

 
        private void toolStripMenuItem16_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.6;
            opacityUncheked();
            toolStripMenuItem16.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("40");
            transparencyWrite.Close();
        }
        private void toolStripMenuItem17_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.5;
            opacityUncheked();
            toolStripMenuItem17.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("50");
            transparencyWrite.Close();
        }
        private void toolStripMenuItem18_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.4;
            opacityUncheked();
            toolStripMenuItem18.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("60");
            transparencyWrite.Close();
        }


         private void toolStripMenuItem19_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.3;
            opacityUncheked();
            toolStripMenuItem19.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("70");
            transparencyWrite.Close();
        }

        private void toolStripMenuItem20_Click(object sender, EventArgs e)
        {
            this.Opacity = 0.2;
            opacityUncheked();
            toolStripMenuItem20.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("80");
            transparencyWrite.Close();
        }

        private void toolStripMenuItem21_Click(object sender, EventArgs e)
        {
            /*

* This is the Last option of the Transparency menu of the Visualization. We can set the set     * the 90% opacity by using this option.
     */

 
            this.Opacity = 0.17;
            opacityUncheked();
            toolStripMenuItem21.Checked = true;
            StreamWriter transparencyWrite = new StreamWriter(@"C:\Program Files\SlideShow\transparency.txt");
            transparencyWrite.Write("90");
            transparencyWrite.Close();
        }
        private void opacityUncheked()
        {

toolStripMenuItem12.Checked = false; toolStripMenuItem13.Checked = false; toolStripMenuItem14.Checked = false; toolStripMenuItem15.Checked = false; toolStripMenuItem16.Checked = false; toolStripMenuItem17.Checked = false;

toolStripMenuItem18.Checked = false; toolStripMenuItem19.Checked = false; toolStripMenuItem20.Checked = false; toolStripMenuItem21.Checked = false;

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {

            /*
* This is the exit menu from that we can quite from the application.
     */

 
            System.Environment.Exit(0);
        }

 
        private void noneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*

*  This is the none option of the BorderStyle submenu of the visualization menu .
            *  By this we can remove the border of the picturebox
     */

 
            this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.None;
            borderUnchecked();
            noneToolStripMenuItem.Checked = true;
            StreamWriter borderWrite = new StreamWriter(@"C:\Program Files\SlideShow\border.txt");
            borderWrite.Write("(None)");
            borderWrite.Close();
        }
       
        private void fixedSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*

*  This is the fixedSingle option of the BorderStyle submenu of the visualization menu .
            *  By this we can apply fixedSingle border style to the picturebox.
     */

 
            this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            borderUnchecked();
            fixedSToolStripMenuItem.Checked = true;          
            StreamWriter borderWrite = new StreamWriter(@"C:\Program Files\SlideShow\border.txt");
            borderWrite.Write("FixedSingle");
            borderWrite.Close();
        }  
       
        private void fixed3DToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*

*  This is the fixed3D option of the BorderStyle submenu of the visualization menu .
            *  By this we can apply fixed3D border style to the picturebox.
     */

 
            this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            borderUnchecked();
            fixed3DToolStripMenuItem.Checked = true;
            StreamWriter borderWrite = new StreamWriter(@"C:\Program Files\SlideShow\border.txt");
            borderWrite.Write("Fixed3D");
            borderWrite.Close();
        }

 
        private void borderUnchecked()
        {
            noneToolStripMenuItem.Checked = false;
            fixed3DToolStripMenuItem.Checked = false; fixedSToolStripMenuItem.Checked = false;
        }

 
     /*

*     From here working start of the menu set position. Which enable us to set slideshow
*     application at 9 position of the desktop.
*/

 

int
width, height;
// This function gives us desktop height and width.

        private void formwidth_height()
        {
            width = this.ClientSize.Width;
            height = this.ClientSize.Height;
        }

 
        int pboxposX = 0, pboxposY = 0;
        int position = 1;
        private void rightToolStripMenuItem_Click(object sender, EventArgs e)
        {
            centerRight();          
            position = 1;
            positionUnchecked();
            rightToolStripMenuItem.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("CenterRight");
            positionWrite.Close();
        }

 
        private void centerRight()
        {
            formwidth_height();
            pboxposX = width - pboxsize;
            pboxposY = (height / 2) - (pboxsize) / 2;
            this.pbox.Location = new System.Drawing.Point(pboxposX, pboxposY);
        }

 
        private void leftToolStripMenuItem_Click(object sender, EventArgs e)
        {
            centerLeft();
            position = 4;
            positionUnchecked();
            leftToolStripMenuItem.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("CenterLeft");
            positionWrite.Close();
        }

 
        private void centerLeft()
        {
            formwidth_height();
            pboxposY = (height / 2) - (pboxsize) / 2;
            this.pbox.Location = new System.Drawing.Point(1, pboxposY);
        }
        private void bottomToolStripMenuItem_Click(object sender, EventArgs e)
        {
            centerBottom();
            position = 9;
            positionUnchecked();
            bottomToolStripMenuItem.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("CenterBottom");
            positionWrite.Close();
        }

        private void centerBottom()
        {
            formwidth_height();
            pboxposX = (width) / 2 - (pboxsize) / 2;
            pboxposY = height - pboxsize;
            this.pbox.Location = new System.Drawing.Point(pboxposX, pboxposY);           
        }

        private void topToolStripMenuItem_Click(object sender, EventArgs e)
        {
            centerTop();
            position = 8;
            positionUnchecked();
            topToolStripMenuItem.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("CenterTop");
            positionWrite.Close();
        }

        private void centerTop()
        {
            formwidth_height();
            pboxposX = (width) / 2 - (pboxsize) / 2;
            this.pbox.Location = new System.Drawing.Point(pboxposX, 1);                    
        }

        private void toolStripMenuItem23_Click(object sender, EventArgs e)
        {
            bottomRight();
            position = 3;
            positionUnchecked();
            toolStripMenuItem23.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("BottomRight");
            positionWrite.Close();
        }

        private void bottomRight()
        {
            formwidth_height();
            pboxposX = width - pboxsize;
            pboxposY = height - pboxsize;
            this.pbox.Location = new System.Drawing.Point(pboxposX, pboxposY);         
        }

        private void toolStripMenuItem24_Click(object sender, EventArgs e)
        {
            topRight();
            position = 2;
            positionUnchecked();
            toolStripMenuItem24.Checked =true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("TopRight");
            positionWrite.Close();
         }

        private void topRight()
        {
            formwidth_height();
            pboxposX = width - pboxsize;
            this.pbox.Location = new System.Drawing.Point(pboxposX, 1);          
        }

        private void toolStripMenuItem25_Click(object sender, EventArgs e)
        {
            topLeft();
            position = 5;
            positionUnchecked();
            toolStripMenuItem25.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("TopLeft");
            positionWrite.Close();
        }

 
        private void topLeft()
        {
            this.pbox.Location = new System.Drawing.Point(1, 1);                     
        }

 
        private void toolStripMenuItem26_Click(object sender, EventArgs e)
        {
            botttomLeft();
            position = 6;
            positionUnchecked();
            toolStripMenuItem26.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("BottomLeft");
            positionWrite.Close();
        }

        private void botttomLeft()
        {
            formwidth_height();
            pboxposY = height - pboxsize;
            this.pbox.Location = new System.Drawing.Point(1, pboxposY);
        }

        private void centerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            center();
            position = 7;
            positionUnchecked();
            centerToolStripMenuItem.Checked = true;
            StreamWriter positionWrite = new StreamWriter(@"C:\Program Files\SlideShow\position.txt");
            positionWrite.Write("Center");
            positionWrite.Close();
        }

 
        private void center()
        {
            formwidth_height();
            pboxposX = (width) / 2 - (pboxsize) / 2;
            pboxposY = (height) / 2 - (pboxsize) / 2;
            this.pbox.Location = new System.Drawing.Point(pboxposX, pboxposY);          
        }

        private void positionUnchecked()
        {
            rightToolStripMenuItem.Checked = false; toolStripMenuItem24.Checked = false;
            toolStripMenuItem23.Checked = false; leftToolStripMenuItem.Checked = false;
            toolStripMenuItem25.Checked = false; toolStripMenuItem26.Checked = false;
            centerToolStripMenuItem.Checked = false; topToolStripMenuItem.Checked = false;
            bottomToolStripMenuItem.Checked = false;
        }

     /*

 *   here working ends to set position and Starts to set size of the Sileshow  application.

 */

        int pboxsize=200;
        private void onToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pboxsize = 200;
            pbox.Size = new System.Drawing.Size(pboxsize,pboxsize);
            positionSelection();
            setPositionToolStripMenuItem.Visible = true;
            sizeUncheck();
            onToolStripMenuItem.Checked = true;
            StreamWriter sizeWrite = new StreamWriter(@"C:\Program Files\SlideShow\size.txt");
            sizeWrite.Write("Normal");
            sizeWrite.Close();
        }

        private void offToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pboxsize = 400;
            pbox.Size = new System.Drawing.Size(pboxsize, pboxsize);
            positionSelection();
            setPositionToolStripMenuItem.Visible = true;
            sizeUncheck();
            offToolStripMenuItem.Checked = true;
            StreamWriter sizeWrite = new StreamWriter(@"C:\Program Files\SlideShow\size.txt");
            sizeWrite.Write("Medium");
            sizeWrite.Close();
        }

 
        private void halfToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formwidth_height();
            pboxsize = (width)/2;          
            pbox.Size = new System.Drawing.Size(pboxsize,pboxsize);
            positionSelection();
            setPositionToolStripMenuItem.Visible = true;
            sizeUncheck();
            halfToolStripMenuItem.Checked = true;
            StreamWriter sizeWrite = new StreamWriter(@"C:\Program Files\SlideShow\size.txt");
            sizeWrite.Write("Half");
            sizeWrite.Close();
        }

        private void fullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formwidth_height();
            pbox.Location = new System.Drawing.Point(1,1);   
            pbox.Size = new System.Drawing.Size(width,height);
            setPositionToolStripMenuItem.Visible = false;
            sizeUncheck();
            fullToolStripMenuItem.Checked = true;
            StreamWriter sizeWrite = new StreamWriter(@"C:\Program Files\SlideShow\size.txt");
            sizeWrite.Write("Normal");
            sizeWrite.Close();
        }

        private void sizeUncheck()
        {
            onToolStripMenuItem.Checked = false; offToolStripMenuItem.Checked = false;
            halfToolStripMenuItem.Checked = false; fullToolStripMenuItem.Checked = false;
        }

     /*
*   here working ends of set size to the Sileshow  application.
*/


 
     /*

*  positionSelection() function works to set position as you select .
*/

private void positionSelection()
        {
            int positionNo = position;
            switch (positionNo)
            {
                case 1:
                    centerRight();
                    break;
                case 2:
                    topRight();
                    break;
                case 3:
                    bottomRight();
                    break;
                case 4:
                    centerLeft();
                    break;
                case 5:
                    topLeft();
                    break;
                case 6:
                    botttomLeft();
                    break;
                case 7:
                    center();
                    break;
                case 8:
                    centerTop();
                    break;
                case 9:
                    centerBottom();
                    break;
            }
        }

 
        private void rendomlyToolStripMenuItem_Click(object sender, EventArgs e)
        {
     /*

*   This is randomly option of the Slide Show menu. This option is used to show your images randomly from
*    the folder that you have selected. 
*/

 
            slideshow = 1;
            sequantialyToolStripMenuItem.Checked = false;
            rendomlyToolStripMenuItem.Checked = true;
            StreamWriter showTypeWrite = new StreamWriter(@"C:\Program Files\SlideShow\slideShowType.txt");
            showTypeWrite.Write("Randomly");
            showTypeWrite.Close();
        }

 
        private void sequantialyToolStripMenuItem_Click(object sender, EventArgs e)
        {
     /*

*   This is Sequentially option of the Slide Show menu. This option is used to show your images Sequentially
*   from the folder that you have selected.   
*/

 
            slideshow = 0;
            rendomlyToolStripMenuItem.Checked = false;
            sequantialyToolStripMenuItem.Checked=true;
            StreamWriter showTypeWrite = new StreamWriter(@"C:\Program Files\SlideShow\slideShowType.txt");
            showTypeWrite.Write("Sequentially");
            showTypeWrite.Close();
        }

 
        private void Form1_Load(object sender, EventArgs e)
        {
            bool exist = Directory.Exists(@"C:\Program Files\SlideShow");
            if (exist == true)
            {
     /*

*  When application loaded below functions are called and they take the sattings that you had last chang

*  from the text file which are in C\Program Fies and apply to the application

*/

                 interval();
                transparency();
                border();
                positionLoad();
                slideShowType();
                sizeType();
            }
        }

 
        private void transparency()
        {
            StreamReader transparencyRead = new StreamReader(@"C:\Program Files\SlideShow\transparency.txt");
            string transparent = transparencyRead.ReadLine();
            transparencyRead.Close();
            opacityUncheked();
            if (transparent == "0")           { this.Opacity = 1; toolStripMenuItem12.Checked = true;   }
            else if (transparent == "10") { this.Opacity = 0.9; toolStripMenuItem13.Checked = true; }
            else if (transparent == "20") { this.Opacity = 0.8; toolStripMenuItem14.Checked = true; }
            else if (transparent == "30") { this.Opacity = 0.7; toolStripMenuItem15.Checked = true; }
            else if (transparent == "40") { this.Opacity = 0.6; toolStripMenuItem16.Checked = true; }
            else if (transparent == "50") { this.Opacity = 0.5; toolStripMenuItem17.Checked = true; }
            else if (transparent == "60") { this.Opacity = 0.4; toolStripMenuItem18.Checked = true; }
            else if (transparent == "70") { this.Opacity = 0.3; toolStripMenuItem19.Checked = true; }
            else if (transparent == "80") { this.Opacity = 0.2; toolStripMenuItem20.Checked = true; }
            else if (transparent == "90") { this.Opacity = 0.17; toolStripMenuItem21.Checked = true;}
        }

 
        private void interval()
        {
            StreamReader pathRead = new StreamReader(@"C:\Program Files\SlideShow\path.txt");
            path = pathRead.ReadLine();
            pathRead.Close();

 
            StreamReader intervalRead = new StreamReader(@"C:\Program Files\SlideShow\interval.txt");
            string intreval = intervalRead.ReadLine();
            intervalRead.Close();
            intervalUnchecked();
            slideShowEnable();
            TimerSlideShow.Start();

         if (intreval == "1sec") { TimerSlideShow.Interval = 1000; secondToolStripMenuItem5.Checked = true; }
         else if (intreval == "2sec") { TimerSlideShow.Interval = 2000; toolStripMenuItem27.Checked = true; }
         else if (intreval == "3sec") { TimerSlideShow.Interval = 3000; secondToolStripMenuItem6.Checked = true; }
         else if (intreval == "5sec") { TimerSlideShow.Interval = 5000; secondToolStripMenuItem7.Checked = true; }
         else if (intreval == "10sec") { TimerSlideShow.Interval = 10000; secondToolStripMenuItem8.Checked = true; }
         else if (intreval == "30sec") { TimerSlideShow.Interval = 30000; secondToolStripMenuItem9.Checked = true; }
         else if (intreval == "1min") { TimerSlideShow.Interval = 60000; minuteToolStripMenuItem1.Checked = true; }
         else if (intreval == "3min") { TimerSlideShow.Interval = 180000; minuteToolStripMenuItem2.Checked = true; }
         else if (intreval == "5min") { TimerSlideShow.Interval = 300000; minuteToolStripMenuItem3.Checked = true; }
         else if (intreval == "10min") { TimerSlideShow.Interval = 600000; minuteToolStripMenuItem4.Checked = true; }
         else if(intreval=="static")   {
                TimerSlideShow.Stop();
                staticViewToolStripMenuItem1.Checked = true;
                slideShowDisable();
            }
        }

 
        private void border()
        {
            StreamReader borderRead = new StreamReader(@"C:\Program Files\SlideShow\border.txt");
            string border = borderRead.ReadLine();
            borderRead.Close();
            borderUnchecked();
            if (border == "Fixed3D")
            {
                this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                fixed3DToolStripMenuItem.Checked = true;
            }
            else if (border == "FixedSingle")
            {
                this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                fixedSToolStripMenuItem.Checked = true;
            }
            else if (border == "(None)")
            {
                this.pbox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                noneToolStripMenuItem.Checked = true;
            }
        }

        private void positionLoad()
        {
            StreamReader positionRead = new StreamReader(@"C:\Program Files\SlideShow\position.txt");
            string  setposition= positionRead.ReadLine();
            positionRead.Close();
            positionUnchecked();
            if (setposition == "CenterRight")
            { centerRight();  position = 1;  rightToolStripMenuItem.Checked = true;  }
            else if (setposition == "TopRight")
      {  topRight(); position = 2;  toolStripMenuItem24.Checked = true;  }
            else if (setposition == "BottomRight")
{ bottomRight(); position = 3; toolStripMenuItem23.Checked = true;  }
            else if (setposition == "CenterLeft")
{  centerLeft();  position = 4; leftToolStripMenuItem.Checked = true; }
            else if (setposition == "TopLeft")
{ topLeft();  position = 5; toolStripMenuItem25.Checked = true; }
            else if (setposition == "BottomLeft")
{ botttomLeft();  position = 6;  toolStripMenuItem26.Checked = true;  }
            else if (setposition == "Center")
{ center(); position = 7;  centerToolStripMenuItem.Checked = true; }
            else if (setposition == "CenterTop")
{ centerTop(); position = 8; topToolStripMenuItem.Checked = true;  }
            else if (setposition == "CenterBottom")
{ centerBottom();  position = 9;  bottomToolStripMenuItem.Checked = true; }
        }

        private void slideShowType()
        {
            StreamReader showTypeRead = new StreamReader(@"C:\Program Files\SlideShow\slideShowType.txt");
            string type = showTypeRead.ReadLine();
            showTypeRead.Close();
            if (type == "Sequentially")
            {
                slideshow = 0;
            }
            else
            {
                sequantialyToolStripMenuItem.Checked = false; rendomlyToolStripMenuItem.Checked = true;
                slideshow = 1;
            }
        }

        private void sizeType()
        {
            StreamReader sizeTypeRead = new StreamReader(@"C:\Program Files\SlideShow\size.txt");
            string sizetype = sizeTypeRead.ReadLine();
            sizeTypeRead.Close();
            sizeUncheck();
            //MessageBox.Show(sizetype);
            if (sizetype == "Normal")
            {
                pboxsize = 200;
                pbox.Size = new System.Drawing.Size(pboxsize, pboxsize);
                positionSelection();             
                onToolStripMenuItem.Checked = true;
            }
            else if (sizetype == "Medium")
            {              
                pboxsize = 400;
                pbox.Size = new System.Drawing.Size(pboxsize, pboxsize);
                positionSelection();             
                offToolStripMenuItem.Checked = true;
            }
            else if (sizetype == "Half")
            {
                formwidth_height();
                pboxsize = (width) / 2;
                pbox.Size = new System.Drawing.Size(pboxsize, pboxsize);
                positionSelection();              
                sizeUncheck();
                halfToolStripMenuItem.Checked = true;
            }

        }


Similar Articles