Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

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

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0];

User-Defined Controls

CIS 3260 Sample Final Exam Part II

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

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent()

this.openfiledialog = new System.Windows.Forms.OpenFileDialog(); this.label4 = new System.Windows.Forms.Label(); this.

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

Visual Studio Windows Form Application #1 Basic Form Properties

Avoiding KeyStrokes in Windows Applications using C#

C# and.net (1) cont d

SMITE API Developer Guide TABLE OF CONTENTS

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

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

Nasosoft Barcode for.net

This is the start of the server code

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

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

C# Forms and Events. Evolution of GUIs. Macintosh VT Datavetenskap, Karlstads universitet 1

Web Services in.net (2)

Tutorial 5 Completing the Inventory Application Introducing Programming

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

UNIT III APPLICATION DEVELOPMENT ON.NET

.NET XML Web Services

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

ABSTRACT. In Windows Operating system, Registry is core component and it contains

Example 1: using System.Windows.Forms;

Inheriting Windows Forms with Visual C#.NET

CHAPTER 3. Writing Windows C# Programs. Objects in C#

Towards More Comprehensive Information Retrieval Systems: Entity Extraction Using XSLT

Lampiran B. Program pengendali

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

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

BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How

CALCULATOR APPLICATION

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

Chapter 13: Handling Events

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

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

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

Chapter 2. Ans. C (p. 55) 2. Which is not a control you can find in the Toolbox? A. Label B. PictureBox C. Properties Window D.

Events. Event Handler Arguments 12/12/2017. EEE-425 Programming Languages (2016) 1

PS2 Random Walk Simulator

Windows Forms in Action by Erik Brown Chapter 3. Copyright 2006 Manning Publications

Operatii pop si push-stiva

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

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

UNIT-3. Prepared by R.VINODINI 1

Understanding Events in C#

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

Conventions in this tutorial

Representing Recursive Relationships Using REP++ TreeView

CSIS 1624 CLASS TEST 6

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

EEE-425 Programming Languages (2013) 1

create database ABCD use ABCD create table bolumler ( bolumkodu int primary key, bolumadi varchar(20) )

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

XNA 4.0 RPG Tutorials. Part 11b. Game Editors

EEE-425 Programming Languages (2013) 1

The Microsoft.NET Framework

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

Flag Quiz Application

CSC 330 Object-Oriented Programming. Encapsulation

Chapter 13. Custom Events. Learning Objectives

CIS2052 Advanced Programming I [C# Programming Language]

Skinning Manual v1.0. Skinning Example

Writing Object Oriented Software with C#

Course 3D_MDX: 3D-Graphics with Managed DirectX 9.0 Chapter 6: Mesh Viewer

JAYARAM. Department of Information Technology QUESTION BANK UNIT I BASICS OF C# Integer real single character string

Visual Studio.NET enables quick, drag-and-drop construction of form-based applications

Laboratorio di Ingegneria del Software

Laboratorio di Ingegneria del L-A

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

In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result.

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

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

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

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.

Web Services in.net (6) cont d

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent() call. //

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.

C# winforms gridview

Computer measurement and control

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

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

CSC 211 Intermediate Programming

Course 3D_MDX: 3D-Graphics with Managed DirectX 9.0Chapter C5: Comments to the "Mesh Viewer" Project

Lucrare pentru colocviu de practică

Ingegneria del Software T. Interfaccia utente

Web Services in.net (7)

Savoy ActiveX Control User Guide

For this example, we will set up a small program to display a picture menu for a fast food take-away shop.

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

#pragma comment(lib, "irrklang.lib") #include <windows.h> namespace SuperMetroidCraft {

Course 2DCis: 2D-Computer Graphics with C# Chapter C5: Comments to the Controls Project

How to create a simple ASP.NET page to create/search data on baan using baan logic from the BOBS client sample.

Developing for Mobile Devices Lab (Part 1 of 2)

Type Description Example

Transcription:

Blank Form Industrial Programming Lecture 8: C# GUI Development Industrial Programming 1 Industrial Programming 2 First Form Code using System; using System.Drawing; using System.Windows.Forms; public class HelloWorld : Form static public void Main () Application.Run (new HelloWorld ()); public HelloWorld () Button b = new Button (); b.text = "Click Me!"; b.click += new EventHandler (Button_Click); Controls.Add (b); private void Button_Click (object sender, EventArgs e) MessageBox.Show ("Button Clicked!"); Discussion The main GUI library to import is System.Windows.Forms Our form HelloWorld inherits from the Form class in the above library The form is created by calling Application.Run on an instance of the HelloWorld class. The constructor of the class HelloWorld defines the contents and layout. It also associates an event handler with the button component of the form. This way, on clicking the button the text Button Clicked will appear. Industrial Programming 3 Industrial Programming 4

Example: echo textbox Imported modules for GUI programs: using System; using System.Drawing; using System.Windows.Forms; Example: echo textbox class MForm : Form private Label text; public MForm() Text = "TextBox"; Size = new Size(250, 200); CenterToScreen(); text = new Label(); text.parent = this; text.text = "..."; text.location = new Point(60, 40); text.autosize = true; Industrial Programming 7 TextBox tbox = new TextBox(); tbox.parent = this; tbox.location = new Point(60, 100); tbox.keyup += new KeyEventHandler(OnKeyUp); Industrial Programming 8 Example: echo textbox Discussion void OnKeyUp(object sender, KeyEventArgs e) TextBox tb = (TextBox) sender; this.text.text = tb.text; Main class class MApplication public static void Main() Application.Run(new MForm()); Industrial Programming 9 The main GUI library to import is System.Windows.Forms Our MForm class inherits from Form. The MForm method defines contents and positioning of the form. It also associates an event handler OnKeyUp to the textbox The OnKeyUp handler simply displays the text typed in so far. A standard Main method starts the application. Industrial Programming 10

GUI creation in Visual Studio Form Properties Most of the time you will use Visual Studio to automatically generate the code for a GUI. This way, all the boilerplate code is generated automatically. Only the worker code, such as event handlers, needs to be written explicitly. The best way to learn this is by familiarising yourself with Visual Studio, creating some simple forms. Here is just a small example, demonstrating the structure of the automatically generated code. Industrial Programming 11 Industrial Programming 12 Form Events Adding Numbers Industrial Programming 13 Industrial Programming 14

Generated Code using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 partial class Form1 : Form private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) if (disposing && (components!= null)) components.dispose(); base.dispose(disposing); Industrial Programming 15 public Form1 () this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.textbox1 = new System.Windows.Forms.TextBox(); this.textbox2 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.suspendlayout(); label1 this.label1.autosize = true; this.label1.location = new System.Drawing.Point(33, 40); this.label1.name = "label1"; this.label1.size = new System.Drawing.Size(78, 13); this.label1.tabindex = 0; this.label1.text = "First Number "; label2 this.label2.autosize = true; this.label2.location = new System.Drawing.Point(33, 76); this.label2.name = "label2"; this.label2.size = new System.Drawing.Size(84, 13); this.label2.tabindex = 1; this.label2.text = "Second Number"; Industrial Programming 16 textbox1 this.textbox1.location = new System.Drawing.Point(147, 33); this.textbox1.name = "textbox1"; this.textbox1.size = new System.Drawing.Size(100, 20); this.textbox1.tabindex = 2; textbox2 this.textbox2.location = new System.Drawing.Point(147, 69); this.textbox2.name = "textbox2"; this.textbox2.size = new System.Drawing.Size(100, 20); this.textbox2.tabindex = 3; button1 this.button1.location = new System.Drawing.Point(102, 135); this.button1.name = "button1"; this.button1.size = new System.Drawing.Size(100, 23); this.button1.tabindex = 4; this.button1.text = "Add Numbers"; this.button1.usevisualstylebackcolor = true; this.button1.click += new System.EventHandler(this.button1_Click); label3 this.label3.autosize = true; this.label3.location = new System.Drawing.Point(126, 196); this.label3.name = "label3"; this.label3.size = new System.Drawing.Size(35, 13); this.label3.tabindex = 5; this.label3.text = ""; Industrial Programming 17 Form1 this.autoscaledimensions = new System.Drawing.SizeF(6F, 13F); this.autoscalemode = System.Windows.Forms.AutoScaleMode.Font; this.clientsize = new System.Drawing.Size(292, 266); this.controls.add(this.label3); this.controls.add(this.button1); this.controls.add(this.textbox2); this.controls.add(this.textbox1); this.controls.add(this.label2); this.controls.add(this.label1); this.name = "Form1"; this.text = "Form1"; this.load += new System.EventHandler(this.InitializeComponent); this.resumelayout(false); this.performlayout(); Industrial Programming 18

private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textbox1; private System.Windows.Forms.TextBox textbox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label3; event handlers private void InitializeComponent(object sender, EventArgs e) put intialization code here private void button1_click(object sender, EventArgs e) string invalue1, invalue2; double val1, val2, result; public class MainClass static public void Main () Application.Run (new Form1()); invalue1 = textbox1.text; invalue2 = textbox2.text; val1 = double.parse(invalue1); val2 = double.parse(invalue2); result = val1 + val2; label3.text = result.tostring(); Industrial Programming 19 Industrial Programming 20 Code Exercise Since you use Visual C# to develop this form, Visual Studio will generate the basic coding for all the items that you place in the form. Create a form with several buttons, text boxes, change the properties and define different events associated with the buttons. You have to write your own code when you want to perform any operations on the items, i.e. to handle any events, change the properties etc. Industrial Programming 27 Industrial Programming 28

Various C# tutorials: Useful Links www.functionx.com/vcsharp/index.htm Mono C# Winforms Tutorial: http:zetcode.com/tutorials/monowinformstutorial/ Industrial Programming 29