You can call the project anything you like I will be calling this one project slide show.

Similar documents
We are going to use some graphics and found a nice little batman running GIF, off course you can use any image you want for the project.

Click on the empty form and apply the following options to the properties Windows.

Form Properties Window

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.

Create your own Meme Maker in C#

Start Visual Studio, create a new project called Helicopter Game and press OK

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

Now find the button component in the tool box. [if toolbox isn't present click VIEW on the top and click toolbox]

Start Visual Studio and create a new windows form application under C# programming language. Call this project YouTube Alarm Clock.

This is the empty form we will be working with in this game. Look under the properties window and find the following and change them.

CALCULATOR APPLICATION

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

Conventions in this tutorial

IBSDK Quick Start Tutorial for C# 2010

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

Experiment 5 : Creating a Windows application to interface with 7-Segment LED display

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

CSIS 1624 CLASS TEST 6

NI USB-TC01 Thermocouple Measurement Device

Developing for Mobile Devices Lab (Part 1 of 2)

Visual Basic/C# Programming (330)

Your First Windows Form

Object oriented lab /second year / review/lecturer: yasmin maki

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Quick Guide for the ServoWorks.NET API 2010/7/13

if (say==0) { k.commandtext = "Insert into kullanici(k_adi,sifre) values('" + textbox3.text + "','" + textbox4.text + "')"; k.

Chapter 12. Tool Strips, Status Strips, and Splitters

Visual Basic/C# Programming (330)

Eyes of the Dragon - XNA Part 37 Map Editor Revisited

UNIT-3. Prepared by R.VINODINI 1

XNA 4.0 RPG Tutorials. Part 24. Level Editor Continued

// Program 2 - Extra Credit // CIS // Spring // Due: 3/11/2015. // By: Andrew L. Wright. //Edited by : Ben Spalding

Chapter 6 Dialogs. Creating a Dialog Style Form

Class Test 4. Question 1. Use notepad to create a console application that displays a stick figure. See figure 1. Question 2

Hands-On Lab. Lab: Client Object Model. Lab version: Last updated: 2/23/2011

Writing Your First Autodesk Revit Model Review Plug-In

Savoy ActiveX Control User Guide

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Image Data Binding. Save images in database An image needs large amount of storage space. Only binary variable length fields may hold images.

Activating AspxCodeGen 4.0

Visual C# Program: Simple Game 3

Step 1: Start a GUI Project. Start->New Project->Visual C# ->Windows Forms Application. Name: Wack-A-Gopher. Step 2: Add Content

Representing Recursive Relationships Using REP++ TreeView

Using Template Bookmarks for Automating Microsoft Word Reports

Creating a nice GUI. OpenGL and Windows. Note: VS 2003 shown. Create a new Project

Chapter 1 Getting Started

Hands-On Lab. Getting Started with Office 2010 Development. Lab version: Last updated: 2/23/2011

// Specify SEF file to load. oschema = (edischema) oedidoc.loadschema(spath + sseffilename, SchemaTypeIDConstants. Schema_Standard_Exchange_Format);

Chapter 8 Advanced GUI Features

Inheriting Windows Forms with Visual C#.NET

// Precondition: None // Postcondition: The address' name has been set to the // specified value set;

C:\homeworks\PenAttention_v13_src\PenAttention_v13_src\PenAttention4\PenAttention\PenAttention.cs 1 using System; 2 using System.Diagnostics; 3 using

User-Defined Controls

INFORMATICS LABORATORY WORK #2

// Specify SEF file to load. edischema oschema = oedidoc.loadschema(spath + sseffilename, SchemaTypeIDConstants. Schema_Standard_Exchange_Format);

OhioState::OpenGLPanel. OpenGL and Windows. Public methods. OpenGLPanel : Forms::Control

How do I use BatchProcess

Tutorial 5 Completing the Inventory Application Introducing Programming

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

2.3 Add GDS Google Map to Visual Studio Toolbox and create a simple map project

string spath; string sedifile = "277_005010X228.X12"; string sseffile = "277_005010X228.SemRef.EVAL0.SEF";

Developing for Mobile Devices Lab (Part 2 of 2)

GOOGLE APPS. If you have difficulty using this program, please contact IT Personnel by phone at

LESSON A. The Splash Screen Application

Gathering and Modifying Real-Time Software Data in a Visual Studio Environment Mark Rogers November 6, 2008

} } public void getir() { DataTable dt = vt.dtgetir("select* from stok order by stokadi");

Hands-On Lab (MBL04) Lab Manual Incorporating COM Objects into Your.NET Compact Framework 2.0 Application

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

Flag Quiz Application

II. Programming Technologies

EL-USB-RT API Guide V1.0

Chapter 13 Working with Threads

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

Using Visual Basic Studio 2008

Mainly three tables namely Teacher, Student and Class for small database of a school. are used. The snapshots of all three tables are shown below.

namespace csharp_gen277x214 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

Lecture 8 Building an MDI Application

Serial Communications Part 1 - Graphical User Interfaces

Визуал програмчлал. Багш: Ж. Шинэбаяр /Маг/

Huw Talliss Data Structures and Variables. Variables

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

Answer on Question# Programming, C#

Setting Up the Fotosizer Software

Once you have entered your Google and password, you can click the Sign In button to continue.

XNA 4.0 RPG Tutorials. Part 22. Reading Data

Objects and Classes. Engineering 1D04, Teaching Session 9

LESSON B. The Toolbox Window

Brian Kiser November Vigilant C# 2.5. Commonwealth of Kentucky Frankfort, Kentucky

APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende:

COMPUTER BASICS LESSON 4 COMPUTER OPERATION SYSTEMS. Edited by C. 1Rhodes 9/11

Mr.Kailley s AP Chem programming Unit Set up instruction sheet for PC s (Mac will be kind of similar: good luck) 1) Go to the following website:

Engr 123 Spring 2018 Notes on Visual Studio

CIS 3260 Intro. to Programming with C#

TuneTown Lab Instructions

RegEx - Numbers matching. Below is a sample code to find the existence of integers within a string.

Table of Contents... ii. GO AHEAD BRING YOUR OWN DEVICE TO WORK... 1 Requirements... 1

Overview. Building a Web-Enabled Decision Support System. Integrating DSS in Business Curriculum. Introduction to DatabaseSupport Systems

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Diving into Visual Studio 2015 (Day #5): Debugging Improvements in Visual Studio 2015 (Part 1) -Akhil Mittal

Transcription:

C# Tutorial Load all images from a folder Slide Show In this tutorial we will see how to create a C# slide show where you load everything from a single folder and view them through a timer. This exercise is very useful because it allows us to learn about the various functionalities of C#. Let s get started with this fun tutorial. First create a new C# Windows Form project in visual studio. You can call the project anything you like I will be calling this one project slide show. If your screen is the same asmine then the Tool BOX is hiding at the moment. We need to bring it to view. If you already know how to do it then brilliant however if you do not, no worries we will show you. You can either bring it from the top View -> Toolbox or you can click on the toolbox icon on the left. Either way get it open because we need some windows components to the form. First thing we need a button on the form. Second thing we need is a Label. Now add a picture box to the screen

Now lets the final ingredient the Timer to the stage Picture Box Button Label Timer

Now to improve the readability of this program we need to give these components individual name instead of the stock names such as picturebox1 or button1 lets change the names to the following Component Button Picture Box Label Timer (Name) you will find this in the properties window Playstop Image Filename Leave it to default This is the properties window for the picture box. See where the name is changed from picturebox1 to image. We also need to change one small thing for this picture box. Find the option that says Size Mode Change from normal to Stretch Application Requirement This is auto size the whole image to the size of this picture box. OK so we have gone to the part where the GUI is set up right now but we need to set up the code. Before we do that we need to first understand what it that this program must do. 1. Select a folder 2. Load all images from folder to the program 3. Change image every 3 seconds 4. Load only JPG images from folder 5. Loop through the images doesn t stop until the button is clicked again.

To enter the code view either right click on the form and click view code or press F7 Before we begin we need to import the system IO class for this program. IO will allow us to use the folder selection class. This is your current view on the code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace projectslideshow public partial class Form1 : Form public Form1() InitializeComponent(); Now add the IO under the System.Windows.Forms; line using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; using System.IO; namespace projectslideshow public partial class Form1 : Form public Form1() InitializeComponent(); Now time to add our necessary variables for the program using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace projectslideshow public partial class Form1 : Form int counter = 1; FolderBrowserDialog fbd = new FolderBrowserDialog(); bool playing = false; public Form1() InitializeComponent(); We are declaring a integer called counter and gave it a value of 1. Since we imported the System.IO into our program we can use Folder Browser Dialog Class to ensure we have a folder dialog box to choose the images. Last variable is a Boolean called playing. This will determine what to do when the slide show is playing or not playing. For now lets leave it on False. Now we need to add an event to the button. Go back to the design view and double click on the button. Double click this Once you done that. Visual studio will add the following code automatically in your program.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace projectslideshow public partial class Form1 : Form int counter = 1; FolderBrowserDialog fbd = new FolderBrowserDialog(); bool playing = false; public Form1() InitializeComponent(); private void playstop_click(object sender, EventArgs e) Within the curly brackets we can do our magic. private void playstop_click(object sender, EventArgs e) if (!playing) DialogResult result = fbd.showdialog(); playstop.text = "Stop"; timer1.start(); playing = true; else playstop.text = "Play"; playing = false; timer1.stop(); Lets look at the first part. Inside that if statement we are checking if the playing is false when the button is clicked then we will do the following to it. First we will load the dialog box to choose a folder by intiating the DialogResult class and adding a showdialog() to it. Then we will change the button text to Stop instead of playing

Then we can start our timer that we added before to the form. And finally we will set the playing variable to true. private void playstop_click(object sender, EventArgs e) if (!playing) DialogResult result = fbd.showdialog(); playstop.text = "Stop"; timer1.start(); playing = true; else playstop.text = "Play"; playing = false; timer1.stop(); Now we do the opposite to that first IF in the ELSE because if the slide show is playing then we need to stop it. So we are going to change the button text back to Play and set the Boolean playing to false and finally stop the timer 1. That wasn t complicated was it? Now go back to design view and double click on the timer icon. private void timer1_tick(object sender, EventArgs e) This code above will be added your project. As we did with our button before we can add our code in between the curly brackets Add the following code to the timer function. private void timer1_tick(object sender, EventArgs e) counter++; string[] images = Directory.GetFiles(fbd.SelectedPath, "*.*"); if (counter > images.length - 1) counter = 0; image.image = Image.FromFile(images[counter]); filename.text = images[counter]; //show name of the image

First we have a line called counter++ this is basically going to add 1 to the integer counter which we declared way up top. Second we are declaring a string array where we will store the file names. IMPORTANT string[] images = Directory.GetFiles(fbd.SelectedPath, "*.*"); Look at the line above carefully notice we are using the Directory function to get the files and inside the brackets we are using fbd or file browser directory which we declared earlier in the tutorial. Inside that we are asking for it find a selected PATH and then we will load all file types from that folder. NOW MORE IMPORTANT If you want your program to run smoothly then have a folder where you only have image files for example JPG, GIF or PNG files. If you have other documents such as a word document, text file or spreadsheet the program will crash because it will not be able to load that file in to the picture box. if (counter > images.length - 1) counter = 0; Here we are going to tell the slide show to loop once it reached the last image. So if the counter is larger than the file names in folder meaning we have reached the end then we will reset the counter to 0. image.image = Image.FromFile(images[counter]); This line will load the individual images to the picture box on form. filename.text = images[counter]; //show name of the image And this line will load the file name of those images into the label. Once thing to do before we test the program. Look into the properties panel of the Timer we added to form.

should change every 3 seconds. Change the interval from 100 to 3000 meaning our slide show to Now with that set up let s take a look the folder we have the pictures saved in. I have created an images folder with 4 JPEG and 3 GIF images. Since we will load all of the files from this folder we don t need to specify the names of the files only the types. You know the old saying programming should make your life easier not difficult. Well it s only true sometimes. This folder is saved on the desktop. So hopefully once we click on play it should give us the option to select a folder and then it can start playing the images. We also need to keep in mind that since we will be allowing all files to be loaded into the picture box lets only save image files in the folder. If we have a DOC or TXT of PDF file in there the program can potentially crash.

Time for testing You can click on the play button to start debugging the application click on start debugging. Or you can click on debug on the top and Once we clicked on play the open folder dialog box comes up Image name and directory information is on. The first image is a JPEG and second image is GIF both playing fine.

First image is a JPEG and second image is a GIF cuteeee OMG. Now we have stopped the slide show. Its sooo Hopefully you had fun creating this Slideshow. See you soon on MooICT.com