PS2 Random Walk Simulator

Size: px
Start display at page:

Download "PS2 Random Walk Simulator"

Transcription

1 PS2 Random Walk Simulator Windows Forms Global data using Singletons ArrayList for storing objects Serialization to Files XML Timers Animation This is a fairly extensive Problem Set with several new concepts. I have tried to give you almost all the code you will need. However, its possible I have missed out something. If I do I will post a notice on the Stellar Web Site We are going to develop a Random Walk Simulator. This will involve generating particles and moving them randomly as we time step. We will need to draw the particles on the screen and animate their movement. This problem set will lead you through the steps. First Form Start up a Console Project in Visual Studio. Add a Reference to System.Windows.Forms. Replace the code in Class1.cs with the following code. Windows provides a class called Form (System.Windows.Forms.Form ) that we can use to create a simple form. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; John R. Williams, Kevin Amaratunga 1

2 namespace FirstForm public class Form1 [STAThread] static void Main() Form myform = new Form(); myform.show(); Notice that Show() pops up the Form (and a Dos Window) but then returns and the program exits removing the Form. We can turn off the Dos Window by going into the Project Properties and changing the Output Type to a Windows Application. static void Main() Form myform = new Form(); myform.showdialog(); 2 John R. Williams, Kevin Amaratunga

3 We need a function that does not immediately return but waits for the Form to be killed. The ShowDialog() method will do just that. Now lets add a Button to our Form. static void Main() Form myform = new Form(); myform.text = "My First Form"; Button button1 = new Button(); button1.text = "Click Me"; myform.controls.add(button1); myform.showdialog(); Notice that there is a Button class given to us in.net. We call things like buttons and menus, Controls. We can add text to the button. To display the button we must add it to the Controls collection of the Form. The class Form has an object called Controls (its not a control itself but holds a list of controls and is probably implemented as an ArrayList) that holds all the children controls of the Form. When Form renders itself it goes through that list and renders all the children in it as well. Event Based Programming What we really want is to have a Windows Form that can catch various events, such as a mouse click, and that allows us to then launch certain methods if that event occurs. This style of programming is called Event Based Programming. static void Main() Form myform = new Form(); myform.text = "My First Form"; Application.Run(myForm); To have our program sit in an infinite loop waiting for events we use the Application class s static method Run(). You should see the following Form on your screen. Notice if you click on it nothing happens at present. That s because we haven t programmed anything to happen. Lets see how we can make something happen when we click on the Form. John R. Williams, Kevin Amaratunga 3

4 Inheriting Form Our goal is to produce a customized form that has various buttons and child controls. If we are going to follow the Object Oriented Paradigm we should really create a new class MyForm, say that inherits Form. When we instantiate MyForm we can make sure that all the buttons and child controls we need are added to the Form. public class MyForm : System.Windows.Forms.Form public MyForm() this.text = "My First Form"; Button button1 = new Button(); button1.text = "Click Me"; this.controls.add(button1); [STAThread] static void Main() Application.Run(new MyForm()); 4 John R. Williams, Kevin Amaratunga

5 When we click the Button it get rendered as a depressed button which is neat but nothing else happens. Or at least it appears that nothing happens. When we click the Button, a Mouse Event, is caught by the WindowsXP operating system. The operating system sees that it is meant for the process that is running the Windows Form. The Mouse Event is passed to the Windows Form which is smart enough to know that the Button control should get that event. The Button class has many events pre-built into it. One of them is the Click event delegate. The Button class then FIRES the Click event delegate and any Methods that have been registered with that delegate get fired as well. Here is a list of some of the Events that Button supports: John R. Williams, Kevin Amaratunga 5

6 We ll hand code the Click event into our program. public class MyForm : System.Windows.Forms.Form public MyForm() this.text = "My First Form"; Button button1 = new Button(); button1.text = "Click Me"; this.controls.add(button1); button1.click += new EventHandler(button1_Click); [STAThread] static void Main() Application.Run(new MyForm()); private void button1_click(object sender, EventArgs e) 6 John R. Williams, Kevin Amaratunga

7 MessageBox.Show("Wow Click Me Again"); When the button is clicked the Message Box will now pop up. A Windows Form Project Now that we ve seen how to develop a Form the hard way we can use the Windows Application Project in Visual Studio. Open a new Project in VS and choose Windows Application You should see something like this John R. Williams, Kevin Amaratunga 7

8 Instead of code you will see what is called the Designer. We ll see that it makes UI development easy for us. If you right click and choose View Code you will see the code below (along with some extra clean up code I ve removed for clarity) using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace MyForm /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form private System.ComponentModel.Container components = null; public Form1() InitializeComponent(); #region Windows Form Designer generated code private void InitializeComponent() this.components = new System.ComponentModel.Container(); this.size = new System.Drawing.Size(300,300); this.text = "Form1"; 8 John R. Williams, Kevin Amaratunga

9 #endregion [STAThread] static void Main() Application.Run(new Form1()); You ll recognize this code as being very similar to the code we produced ourselves. Beware: The IDE Designer needs control of the InitializeComponent and you should not make any changes there. If you do they may be lost. In class we saw how to add buttons and other things using the Designer. Now that we can handle Forms lets do an Exercise. John R. Williams, Kevin Amaratunga 9

10 Exercise Stage 1 Simple Design The user can create a number of shapes including Dots and Circles. We will first write the code to create Dots. The user creates a Dot by entering coordinates in the textboxes and then clicking on Make Shape. For now all objects are a fixed size. 10 John R. Williams, Kevin Amaratunga

11 We want to keep track of the total number of objects (every time we create one we need to increment a counter. See Appendix on Singleton). We will add more requirements later but for now let s see how we can implement this. We need to construct the following classes: class Shape - we ll make this a Base class so that all kinds of objects at least have this functionality Shape objects should have a Centroid, a color and be able to Draw themselves on the screen and be able to Move. class Dot:Shape This is a simple class that we will use to display Points on the Form class Circle: Shape Circle inherits Shape and should override the Draw method Drawing the objects on the screen Storing the objects in a collection of some kind so we can manipulate all of them easily Drawing Objects You can draw object directly onto a Form or you can use a PictureBox control. The latter is preferable because it supports Double Buffering so that animation is smooth and without flicker. We will use a PictureBox. The PictureBox control has a Paint event that is fired whenever the PictureBox needs to be redrawn or when we force it to be redrawn. We can add our own delegate method to the Paint event by double clicking on Paint in the Properties window of VS. John R. Williams, Kevin Amaratunga 11

12 private void picturebox1_paint(object sender, System.Windows.Forms.PaintEventArgs e) // Graphics g = e.graphics; // loop over all objects that need to be drawn - obj // obj.draw(graphics g); The Graphics object knows how to draw circles, arcs, squares and all kinds of useful shapes. Every Shape that we create will need its own Draw method so that it can draw itself when required. Storing Objects We also need to think about how we will manage the objects that we create. We ll do that by creating a World class that has an ArrayList into which we can place objects. Classes 12 John R. Williams, Kevin Amaratunga

13 Here is some code for the classes that you need. Base class Shape abstract public class Shape Point centroid; public Shape() ShapeCounter.counter.Increment(); centroid = new Point(0,0); public Point Centroid getreturn centroid; setcentroid = value; abstract public void Draw(Graphics g); Notice that we are using ShapeCounter. This is another class called a Singleton class. Read about this in the Appendix. Here is its implementation. public class ShapeCounter public static readonly ShapeCounter counter = new ShapeCounter(); private ShapeCounter() private int count = 0; public int Count setcount = value; getreturn count; public int Increment() return count++; This is a very slick class. See if you can see why its written the way it is. Its based on the Design Pattern shown here.net Singleton Example //.NET Singleton sealed class Singleton private Singleton() John R. Williams, Kevin Amaratunga 13

14 public static readonly Singleton Instance = new Singleton(); Derived class Dot public class Dot:Shape public Dot():base() public override void Draw(System.Drawing.Graphics g) g.fillellipse(brushes.red, Centroid.X,Centroid.Y,5,5); Derived class Circle public class Circle:Shape private int radius; public Circle():base() // Default Constructor public Circle(int rad):base() radius = rad; public int Radius getreturn radius; setradius = value; public override void Draw(System.Drawing.Graphics g) g.fillellipse(brushes.blue, Centroid.X,Centroid.Y,Radius,Radius); World Storage Class for Objects public class World public static World myworld = new World(); public World() static World() World.myWorld.worldList = new ArrayList(); private ArrayList worldlist; public ArrayList WorldList 14 John R. Williams, Kevin Amaratunga

15 getreturn worldlist; public static void Draw(Graphics g) foreach(shape s in World.myWorld.WorldList) s.draw(g); Making Objects Here is some code that will make a Dot object when the button is clicked. Notice that we can move the Dot to a new position by changing its Centroid. We could possibly do this dynamically and animate the Dots so that move around. We ll maybe do that later. private void button1_click(object sender, System.EventArgs e) // create a dot Dot d = new Dot(); // maybe we should pass in Centroid int x = Convert.ToInt32(this.textBox1.Text); int y = Convert.ToInt32(this.textBox2.Text); d.centroid = new Point(x,y); World.myWorld.WorldList.Add(d); this.textbox3.text = ShapeCounter.counter.Count.ToString(); this.refresh(); Make sure you get this to work before going any further. Adding Circles Now change the User Interface so that you have a second button called Circle that adds a circle at the given coordinates. For now make the radius a fixed size. The code will look almost exactly like the button_click above but you need to create a Circle instead of a Dot. John R. Williams, Kevin Amaratunga 15

16 Stage 2 - Serializing the World to a File One of the things that would be good to do would be to be able to store our World as a file. There is an easy way to do this and its called Serialization. Basically, serialization takes complex types like Circle or Dot and expresses them in terms of their in-built types, such as int etc. It does this by creating XML. We haven t talked about XML yet but you can still use it without really knowing too much about it. Here is what the serialized World looks like when it contains a Dot, a Circle and another Dot. <?xml version="1.0" encoding="utf-8"?> <World xmlns:xsd=" xmlns:xsi=" <WorldList> <Dot> <Centroid> <X>50</X> <Y>70</Y> </Centroid> </Dot> <Circle> <Centroid> <X>50</X> <Y>170</Y> </Centroid> <Radius>40</Radius> </Circle> <Dot> <Centroid> <X>15</X> <Y>170</Y> </Centroid> </Dot> </WorldList> </World> Here is the code to serialize and deserialize the World. Put it in the World class. 16 John R. Williams, Kevin Amaratunga

17 public void Serialize() XmlSerializer myserializer = new XmlSerializer(typeof(World)); // To write to a file, create a StreamWriter object. StreamWriter mywriter = new StreamWriter("World.xml"); myserializer.serialize(mywriter, myworld); mywriter.close(); public void DeSerialize() XmlSerializer myserializer = new XmlSerializer(typeof(World)); // To write to a file, create a StreamWriter object. StreamReader myreader = new StreamReader("World.xml"); myworld = (World)mySerializer.Deserialize(myReader); myreader.close(); In order to make serialization work we also need to do the following: 1. using System.Xml.Serialization; 2. put [Serializable] on the Dot and Circle class [Serializable] public class Circle:Shape Also when we store objects, such as Circle and Dot in an ArrayList we need to give the ArrayList some clues about how to serialize the objects. We do this by adding [XmlArrayItem(typeof(Dot),ElementName = "Dot")] [XmlArrayItem(typeof(Circle),ElementName = "Circle")] as shown in the code below [Serializable] public class World public static World myworld = new World(); public World() static World() World.myWorld.worldList = new ArrayList(); private ArrayList worldlist; [XmlArrayItem(typeof(Dot),ElementName = "Dot")] [XmlArrayItem(typeof(Circle),ElementName = "Circle")] public ArrayList WorldList getreturn worldlist; setworldlist = value; John R. Williams, Kevin Amaratunga 17

18 Here are some things you need to know about Serialization. Only classes marked [Serializable] will be serialized There must be a public constructor for the class (I had to add one to Circle and you should do the same) Only members of the class marked public will be serialized (in the code above the private ArrayList worldlist is NOT serialized but the public ArrayList WorldList property IS serialized. Notice we only need one of them to get the information we want written out. Modify the design of your code as shown below so that the Serialize button Serializes the World to the file World.xml. Notice that it writes the file under the bin/debug directory. The Clear All button should clear the World ArrayList of all objects. Then DeSerialize should re-create the World by reading from the file World.xml. This is really neat. Now we can edit the World.xml file by hand and say add in new objects. Then when we read it back in all the new objects will be automatically created. 18 John R. Williams, Kevin Amaratunga

19 John R. Williams, Kevin Amaratunga 19

20 You should now have a program that looks like this. 20 John R. Williams, Kevin Amaratunga

21 See if you can read in this file. If it looks different to yours then don t spend too much time on it. Your code may just be a little different to mine. However, wouldn t it be neat if we could exchange files and I could define say a complete model for you just by giving you an XML file. <?xml version="1.0" encoding="utf-8"?> <World xmlns:xsd=" xmlns:xsi=" <WorldList> <Dot> <Centroid> <X>50</X> <Y>70</Y> </Centroid> </Dot> <Circle> <Centroid> <X>50</X> <Y>87</Y> </Centroid> <Radius>40</Radius> </Circle> <Dot> <Centroid> <X>150</X> <Y>87</Y> John R. Williams, Kevin Amaratunga 21

22 </Centroid> </Dot> <Circle> <Centroid> <X>150</X> <Y>187</Y> </Centroid> <Radius>40</Radius> </Circle> <Dot> <Centroid> <X>150</X> <Y>17</Y> </Centroid> </Dot> <Dot> <Centroid> <X>10</X> <Y>17</Y> </Centroid> </Dot> </WorldList> </World> Here is what it should look like (I may have the extra Animate button). 22 John R. Williams, Kevin Amaratunga

23 Stage 3 Animation We want to move our objects around so they behave like molecules bouncing around a box. Lets see if we can figure out how to do this. We know we can update the position of Dots and Circles by changing their Centroid (which is part of the Shape base class). So if we update each Shape and then Redraw all the objects maybe it will look like animation. We need some kind of Timer so that every tick we move the objects and redraw. Fortunately there is one available. From the ToolBox drag a Timer onto the Form. This will create a Timer object called timer1. Double click on the Timer in the Designer and it will automatically create an Event called Tick and a function called timer1_tick Here is my version of what we should do every time there is a Tick event. private void timer1_tick(object sender, System.EventArgs e) // update the positions of the objects Random random = new Random(9); foreach(shape s in World.myWorld.WorldList) int newx = s.centroid.x + random.next(4); int newy = s.centroid.y + random.next(5); s.centroid = new Point(newx,newy); this.refresh(); You may need to set the timer Interval (the time between ticks in milliseconds (1000 = 1sec) timer1.interval = 200 say. You should see the Timer on the Designer as shown below. John R. Williams, Kevin Amaratunga 23

24 The Random Walk Simulator You now have all the tools you need to make the Random Walk Simulator. Below is an example of the one I wrote. It generates particles every time step at the origin. It applies a bias to the random motion so as to simulate a wind say dispersing particles from a chimney stack. The Animate button sets the simulator in motion. I can alter the speed at which it runs using the slider at the bottom. Think about how you will manage the particles so that you don t waste CPU cycles. For example, once the particles move out of the Problem Space you might want to destroy them. Otherwise, we will end up simulating ever more particles. 24 John R. Williams, Kevin Amaratunga

25 John R. Williams, Kevin Amaratunga 25

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

Classes in C# namespace classtest { public class myclass { public myclass() { } } } Classes in C# A class is of similar function to our previously used Active X components. The difference between the two is the components are registered with windows and can be shared by different applications,

More information

User-Defined Controls

User-Defined Controls C# cont d (C-sharp) (many of these slides are extracted and adapted from Deitel s book and slides, How to Program in C#. They are provided for CSE3403 students only. Not to be published or publicly distributed

More information

Smoother Graphics Taking Control of Painting the Screen

Smoother Graphics Taking Control of Painting the Screen It is very likely that by now you ve tried something that made your game run rather slow. Perhaps you tried to use an image with a transparent background, or had a gazillion objects moving on the window

More information

Create a memory DC for double buffering

Create a memory DC for double buffering Animation Animation is implemented as follows: Create a memory DC for double buffering Every so many milliseconds, update the image in the memory DC to reflect the motion since the last update, and then

More information

Spell Casting Motion Pack 5/5/2017

Spell Casting Motion Pack 5/5/2017 The Spell Casting Motion pack requires the following: Motion Controller v2.49 or higher Mixamo s free Pro Magic Pack (using Y Bot) Importing and running without these assets will generate errors! Overview

More information

CALCULATOR APPLICATION

CALCULATOR APPLICATION CALCULATOR APPLICATION Form1.cs 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;

More information

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

You can call the project anything you like I will be calling this one project slide show. 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

More information

Inheriting Windows Forms with Visual C#.NET

Inheriting Windows Forms with Visual C#.NET Inheriting Windows Forms with Visual C#.NET Overview In order to understand the power of OOP, consider, for example, form inheritance, a new feature of.net that lets you create a base form that becomes

More information

(0,0) (600, 400) CS109. PictureBox and Timer Controls

(0,0) (600, 400) CS109. PictureBox and Timer Controls CS109 PictureBox and Timer Controls Let s take a little diversion and discuss how to draw some simple graphics. Graphics are not covered in the book, so you ll have to use these notes (or the built-in

More information

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

Now find the button component in the tool box. [if toolbox isn't present click VIEW on the top and click toolbox] C# Tutorial - Create a Tic Tac Toe game with Working AI This project will be created in Visual Studio 2010 however you can use any version of Visual Studio to follow along this tutorial. To start open

More information

UNIT-3. Prepared by R.VINODINI 1

UNIT-3. Prepared by R.VINODINI 1 Prepared by R.VINODINI 1 Prepared by R.VINODINI 2 Prepared by R.VINODINI 3 Prepared by R.VINODINI 4 Prepared by R.VINODINI 5 o o o o Prepared by R.VINODINI 6 Prepared by R.VINODINI 7 Prepared by R.VINODINI

More information

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

Click on the empty form and apply the following options to the properties Windows. Start New Project In Visual Studio Choose C# Windows Form Application Name it SpaceInvaders and Click OK. Click on the empty form and apply the following options to the properties Windows. This is the

More information

Your First Windows Form

Your First Windows Form Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

More information

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

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Outline 6.1 Test-Driving the Enhanced Inventory Application 6.2 Variables 6.3 Handling the TextChanged

More information

Overview Describe the structure of a Windows Forms application Introduce deployment over networks

Overview Describe the structure of a Windows Forms application Introduce deployment over networks Windows Forms Overview Describe the structure of a Windows Forms application application entry point forms components and controls Introduce deployment over networks 2 Windows Forms Windows Forms are classes

More information

Tutorial 5 Completing the Inventory Application Introducing Programming

Tutorial 5 Completing the Inventory Application Introducing Programming 1 Tutorial 5 Completing the Inventory Application Introducing Programming Outline 5.1 Test-Driving the Inventory Application 5.2 Introduction to C# Code 5.3 Inserting an Event Handler 5.4 Performing a

More information

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list C# cont d (C-sharp) (many of these slides are extracted and adapted from Deitel s book and slides, How to Program in C#. They are provided for CSE3403 students only. Not to be published or publicly distributed

More information

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

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; Exercise 9.3 In Form1.h #pragma once #include "Form2.h" Add to the beginning of Form1.h #include #include For srand() s input parameter namespace Tst_Form using namespace System; using

More information

Capturing the Mouse. Dragging Example

Capturing the Mouse. Dragging Example Capturing the Mouse In order to allow the user to drag something, you need to keep track of whether the mouse is "down" or "up". It is "down" from the MouseDown event to the subsequent MouseUp event. What

More information

Web Services in.net (2)

Web Services in.net (2) Web Services in.net (2) These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial

More information

The Network. Multithreading. This tutorial can be found on -

The Network. Multithreading. This tutorial can be found on - This tutorial can be found on - http://www.informit.com/articles/article.aspx?p=25462&seqnum=5 Instant messaging is sweeping the world, and is rapidly replacing email as the preferred electronic communications

More information

Menus and Printing. Menus. A focal point of most Windows applications

Menus and Printing. Menus. A focal point of most Windows applications Menus and Printing Menus A focal point of most Windows applications Almost all applications have a MainMenu Bar or MenuStrip MainMenu Bar or MenuStrip resides under the title bar MainMenu or MenuStrip

More information

Form Properties Window

Form Properties Window C# Tutorial Create a Save The Eggs Item Drop Game in Visual Studio Start Visual Studio, Start a new project. Under the C# language, choose Windows Form Application. Name the project savetheeggs and click

More information

This is the start of the server code

This is the start of the server code This is the start of the server code using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets;

More information

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

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points Assignment 1 Lights Out! in C# GUI Programming 10 points Introduction In this lab you will create a simple C# application with a menu, some buttons, and an About dialog box. You will learn how to create

More information

Laboratorio di Ingegneria del Software

Laboratorio di Ingegneria del Software Laboratorio di Ingegneria del Software L-A Interfaccia utente System.Windows.Forms The System.Windows.Forms namespace contains classes for creating Windows-based applications The classes can be grouped

More information

Laboratorio di Ingegneria del L-A

Laboratorio di Ingegneria del L-A Software L-A Interfaccia utente System.Windows.Forms The System.Windows.Forms namespace contains classes for creating Windows-based applications The classes can be grouped into the following categories:

More information

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Additional Controls, Scope, Random Numbers, and Graphics CS109 In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Combo

More information

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

Quick Guide for the ServoWorks.NET API 2010/7/13 Quick Guide for the ServoWorks.NET API 2010/7/13 This document will guide you through creating a simple sample application that jogs axis 1 in a single direction using Soft Servo Systems ServoWorks.NET

More information

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..

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.. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

More information

Ingegneria del Software T. Interfaccia utente

Ingegneria del Software T. Interfaccia utente Interfaccia utente Creating Windows Applications Typical windows-application design & development 1+ classes derived from System.Windows.Forms.Form Design UI with VisualStudio.NET Possible to do anything

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

Developing for Mobile Devices Lab (Part 1 of 2)

Developing for Mobile Devices Lab (Part 1 of 2) Developing for Mobile Devices Lab (Part 1 of 2) Overview Through these two lab sessions you will learn how to create mobile applications for Windows Mobile phones and PDAs. As developing for Windows Mobile

More information

Visual C# Program: Simple Game 3

Visual C# Program: Simple Game 3 C h a p t e r 6C Visual C# Program: Simple Game 3 In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Opening Visual C# Editor Beginning a

More information

Let s Make a Front Panel using FrontCAD

Let s Make a Front Panel using FrontCAD Let s Make a Front Panel using FrontCAD By Jim Patchell FrontCad is meant to be a simple, easy to use CAD program for creating front panel designs and artwork. It is a free, open source program, with the

More information

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6. C# cont d (C-sharp) (many of these slides are extracted and adapted from Deitel s book and slides, How to Program in C#. They are provided for CSE3403 students only. Not to be published or publicly distributed

More information

Understanding Events in C#

Understanding Events in C# Understanding Events in C# Introduction Events are one of the core and important concepts of C#.Net Programming environment and frankly speaking sometimes it s hard to understand them without proper explanation

More information

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

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects 1 Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline 19.1 Test-Driving the Microwave Oven Application 19.2 Designing the Microwave Oven Application 19.3 Adding a New

More information

Event-based Programming

Event-based Programming Window-based programming Roger Crawfis Most modern desktop systems are window-based. What location do I use to set this pixel? Non-window based environment Window based environment Window-based GUI s are

More information

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

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK. Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK. Before you start - download the game assets from above or on MOOICT.COM to

More information

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

Creating a nice GUI. OpenGL and Windows. Note: VS 2003 shown. Create a new Project Creating a nice GUI OpenGL and Windows Windows Forms Programming Roger Crawfis The next several slides will walk you thru a particular design that I like for my applications. The order can be a little

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 31 Static Members Welcome to Module 16 of Programming in C++.

More information

DRAWING AND MOVING IMAGES

DRAWING AND MOVING IMAGES DRAWING AND MOVING IMAGES Moving images and shapes in a Visual Basic application simply requires the user of a Timer that changes the x- and y-positions every time the Timer ticks. In our first example,

More information

Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill

Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill Developing Desktop Apps for Ultrabook Devices in Windows* 8: Adapting Existing Apps By Paul Ferrill Microsoft introduced the Extensible Application Markup Language (XAML) in conjunction with the release

More information

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN Contents Contents 5 About the Author 12 Introduction 13 Conventions used in this book 14 1 The Visual Studio C# Environment 15 1.1 Introduction 15 1.2 Obtaining the C# software 15 1.3 The Visual Studio

More information

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

Experiment 5 : Creating a Windows application to interface with 7-Segment LED display Experiment 5 : Creating a Windows application to interface with 7-Segment LED display Objectives : 1) To understand the how Windows Forms in the Windows-based applications. 2) To create a Window Application

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

Web Services in.net (7)

Web Services in.net (7) Web Services in.net (7) These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial

More information

Instructions for Crossword Assignment CS130

Instructions for Crossword Assignment CS130 Instructions for Crossword Assignment CS130 Purposes: Implement a keyboard interface. 1. The program you will build is meant to assist a person in preparing a crossword puzzle for publication. You have

More information

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

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer C# Tutorial Create a Motivational Quotes Viewer Application in Visual Studio In this tutorial we will create a fun little application for Microsoft Windows using Visual Studio. You can use any version

More information

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

OhioState::OpenGLPanel. OpenGL and Windows. Public methods. OpenGLPanel : Forms::Control OhioState::OpenGLPanel OpenGL and Windows Windows Forms Programming Roger Crawfis The simplest possible canvas or rendering context. No assumptions are made (single buffer, double buffer, etc.) Burden

More information

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

Now it only remains to supply the code. Begin by creating three fonts:

Now it only remains to supply the code. Begin by creating three fonts: Owner-Draw Menus Normal menus are always drawn in the same font and the same size. But sometimes, this may not be enough for your purposes. For example, here is a screen shot from MathXpert: Notice in

More information

CSIS 1624 CLASS TEST 6

CSIS 1624 CLASS TEST 6 CSIS 1624 CLASS TEST 6 Instructions: Use visual studio 2012/2013 Make sure your work is saved correctly Submit your work as instructed by the demmies. This is an open-book test. You may consult the printed

More information

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

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at: This document describes how to create a simple Windows Forms Application using some Open Core Interface functions in C# with Microsoft Visual Studio Express 2013. 1 Preconditions The Open Core Interface

More information

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2 Worksheet #2 Overview For this worksheet, we will create a class library and then use the resulting dynamic link library (DLL) in a console application. This worksheet is a start on your next programming

More information

Load your files from the end of Lab A, since these will be your starting point.

Load your files from the end of Lab A, since these will be your starting point. Coursework Lab B It is extremely important that you finish lab A first, otherwise this lab session will probably not make sense to you. Lab B gives you a lot of the background and basics. The aim of the

More information

Class Test 5. Create a simple paint program that conforms to the following requirements.

Class Test 5. Create a simple paint program that conforms to the following requirements. Class Test 5 Question 1 Use visual studio 2012 ultimate to create a C# windows forms application. Create a simple paint program that conforms to the following requirements. The control box is disabled

More information

1. Defining Procedures and Reusing Blocks

1. Defining Procedures and Reusing Blocks 1. Defining Procedures and Reusing Blocks 1.1 Eliminating Redundancy By creating a procedure, move a copy of the redundant blocks into it, and then call the procedure from the places containing the redundant

More information

Add in a new balloon sprite, and a suitable stage backdrop.

Add in a new balloon sprite, and a suitable stage backdrop. Balloons Introduction You are going to make a balloon-popping game! Step 1: Animating a balloon Activity Checklist Start a new Scratch project, and delete the cat sprite so that your project is empty.

More information

The Microsoft.NET Framework

The Microsoft.NET Framework Microsoft Visual Studio 2005/2008 and the.net Framework The Microsoft.NET Framework The Common Language Runtime Common Language Specification Programming Languages C#, Visual Basic, C++, lots of others

More information

Chapter 6 Dialogs. Creating a Dialog Style Form

Chapter 6 Dialogs. Creating a Dialog Style Form Chapter 6 Dialogs We all know the importance of dialogs in Windows applications. Dialogs using the.net FCL are very easy to implement if you already know how to use basic controls on forms. A dialog is

More information

In-Class Worksheet #4

In-Class Worksheet #4 CSE 459.24 Programming in C# Richard Kidwell In-Class Worksheet #4 Creating a Windows Forms application with Data Binding You should have Visual Studio 2008 open. 1. Create a new Project either from the

More information

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created. + Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create

More information

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

Start Visual Studio, create a new project called Helicopter Game and press OK C# Tutorial Create a helicopter flying and shooting game in visual studio In this tutorial we will create a fun little helicopter game in visual studio. You will be flying the helicopter which can shoot

More information

OGSI.NET UVa Grid Computing Group. OGSI.NET Developer Tutorial

OGSI.NET UVa Grid Computing Group. OGSI.NET Developer Tutorial OGSI.NET UVa Grid Computing Group OGSI.NET Developer Tutorial Table of Contents Table of Contents...2 Introduction...3 Writing a Simple Service...4 Simple Math Port Type...4 Simple Math Service and Bindings...7

More information

Lampiran B. Program pengendali

Lampiran B. Program pengendali Lampiran B Program pengendali #pragma once namespace serial using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms;

More information

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and

More information

Starting Visual Studio 2005

Starting Visual Studio 2005 Starting Visual Studio 2005 1 Startup Language 1. Select Language 2. Start Visual Studio If this is your first time starting VS2005 after installation, you will probably see this screen. It is asking you

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Java Graphics and GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Review: how to create

More information

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0. Sub To Srt Converter This is the source code of this program. It is made in C# with.net 2.0. form1.css /* * Name: Sub to srt converter * Programmer: Paunoiu Alexandru Dumitru * Date: 5.11.2007 * Description:

More information

Writing Object Oriented Software with C#

Writing Object Oriented Software with C# Writing Object Oriented Software with C# C# and OOP C# is designed for the.net Framework The.NET Framework is Object Oriented In C# Your access to the OS is through objects You have the ability to create

More information

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL: Send SMS via SOAP API Introduction You can seamlessly integrate your applications with aql's outbound SMS messaging service via SOAP using our SOAP API. Sending messages via the SOAP gateway WSDL file

More information

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

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear. 4 Programming with C#.NET 1 Camera The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear. Begin by loading Microsoft Visual Studio

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

More information

CISC 1600, Lab 2.3: Processing animation, objects, and arrays

CISC 1600, Lab 2.3: Processing animation, objects, and arrays CISC 1600, Lab 2.3: Processing animation, objects, and arrays Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad. sketchpad.cc in your browser and log in. Go to http://cisc1600.

More information

Menus. You ll find MenuStrip listed in the Toolbox. Drag one to your form. Where it says Type Here, type Weather. Then you ll see this:

Menus. You ll find MenuStrip listed in the Toolbox. Drag one to your form. Where it says Type Here, type Weather. Then you ll see this: Menus In.NET, a menu is just another object that you can add to your form. You can add objects to your form by drop-and-drag from the Toolbox. If you don t see the toolbox, choose View Toolbox in the main

More information

More Language Features and Windows Forms

More Language Features and Windows Forms More Language Features and Windows Forms C# Programming January 12 Part I Some Language Features Inheritance To extend a class A: class B : A {... } B inherits all instance variables and methods of A Which

More information

More Language Features and Windows Forms. Part I. Some Language Features. Inheritance. Inheritance. Inheritance. Inheritance.

More Language Features and Windows Forms. Part I. Some Language Features. Inheritance. Inheritance. Inheritance. Inheritance. More Language Features and Windows Forms C# Programming Part I Some Language Features January 12 To extend a class A: class B : A { B inherits all instance variables and methods of A Which ones it can

More information

App #2 - Paint Pot. Getting Ready. Objectives: In this lesson you will learn to:

App #2 - Paint Pot. Getting Ready. Objectives: In this lesson you will learn to: App #2 - Paint Pot Paint Pot is a basic finger painting app. It simulates the process of dipping your finger in a pot of a paint and then drawing on a canvas. The app uses buttons to simulate dipping your

More information

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 Object hierarchies Overview Several classes inheriting from same base class Concrete versus abstract classes

More information

Web Services in.net (6) cont d

Web Services in.net (6) cont d Web Services in.net (6) cont d These slides are meant to be for teaching purposes only and only for the students that are registered in CSE3403 and should not be published as a book or in any form of commercial

More information

Skinning Manual v1.0. Skinning Example

Skinning Manual v1.0. Skinning Example Skinning Manual v1.0 Introduction Centroid Skinning, available in CNC11 v3.15 r24+ for Mill and Lathe, allows developers to create their own front-end or skin for their application. Skinning allows developers

More information

Create your own Meme Maker in C#

Create your own Meme Maker in C# Create your own Meme Maker in C# This tutorial will show how to create a meme maker in visual studio 2010 using C#. Now we are using Visual Studio 2010 version you can use any and still get the same result.

More information

Conventions in this tutorial

Conventions in this tutorial This document provides an exercise using Digi JumpStart for Windows Embedded CE 6.0. This document shows how to develop, run, and debug a simple application on your target hardware platform. This tutorial

More information

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via  by Friday, Mar. 18, 2016 Math 304 - Dr. Miller - Constructing in Sketchpad (tm) - Due via email by Friday, Mar. 18, 2016 As with our second GSP activity for this course, you will email the assignment at the end of this tutorial

More information

Operatii pop si push-stiva

Operatii pop si push-stiva Operatii pop si push-stiva Aplicatia realizata in Microsoft Visual Studio C++ 2010 permite simularea operatiilor de introducere si extragere a elementelor dintr-o structura de tip stiva.pentru aceasta

More information

CS12020 for CGVG. Practical 1. Jim Finnis

CS12020 for CGVG. Practical 1. Jim Finnis CS12020 for CGVG Practical 1 Jim Finnis (jcf1@aber.ac.uk) About me 20 years in the games industry (more or less) Windows, PS2, Xbox, Gamecube, Wii development experience DirectX (more than I like to think

More information

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.

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. We are working on Visual Studio 2010 but this project can be remade in any other version of visual studio. Start a new project in Visual Studio, make this a C# Windows Form Application and name it zombieshooter.

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

Langage C# et environnement.net M1 Année

Langage C# et environnement.net M1 Année Cahier de TP C# et.net SÉANCE 1 : BASIC OOL CONCEPTS...1 SÉANCE 2 : DELEGATES, EVENTS, THREAD-SAFE CONTROL ACCESS, RESOURCE MANAGEMENT...3 SÉANCE 3 : INHERITANCE, POLYMORPHISM, CONTAINERS, SERIALIZATION...5

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Animations that make decisions

Animations that make decisions Chapter 17 Animations that make decisions 17.1 String decisions Worked Exercise 17.1.1 Develop an animation of a simple traffic light. It should initially show a green disk; after 5 seconds, it should

More information

Responding to the Mouse

Responding to the Mouse Responding to the Mouse The mouse has two buttons: left and right. Each button can be depressed and can be released. Here, for reference are the definitions of three common terms for actions performed

More information

Flag Quiz Application

Flag Quiz Application T U T O R I A L 17 Objectives In this tutorial, you will learn to: Create and initialize arrays. Store information in an array. Refer to individual elements of an array. Sort arrays. Use ComboBoxes to

More information

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

string spath; string sedifile = 277_005010X228.X12; string sseffile = 277_005010X228.SemRef.EVAL0.SEF; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Edidev.FrameworkEDI; 1 namespace

More information

Visual Basic/C# Programming (330)

Visual Basic/C# Programming (330) Page 1 of 12 Visual Basic/C# Programming (330) REGIONAL 2017 Production Portion: Program 1: Calendar Analysis (400 points) TOTAL POINTS (400 points) Judge/Graders: Please double check and verify all scores

More information

Adobe Flash CS3 Reference Flash CS3 Application Window

Adobe Flash CS3 Reference Flash CS3 Application Window Adobe Flash CS3 Reference Flash CS3 Application Window When you load up Flash CS3 and choose to create a new Flash document, the application window should look something like the screenshot below. Layers

More information

FACULTY AND STAFF COMPUTER FOOTHILL-DE ANZA. Office Graphics

FACULTY AND STAFF COMPUTER FOOTHILL-DE ANZA. Office Graphics FACULTY AND STAFF COMPUTER TRAINING @ FOOTHILL-DE ANZA Office 2001 Graphics Microsoft Clip Art Introduction Office 2001 wants to be the application that does everything, including Windows! When it comes

More information