User-Defined Controls

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

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

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

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

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

C# and.net (1) cont d

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

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

This is the start of the server code

CIS 3260 Sample Final Exam Part II

Tutorial 5 Completing the Inventory Application Introducing Programming

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

Avoiding KeyStrokes in Windows Applications using C#

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

Visual Studio Windows Form Application #1 Basic Form Properties

Web Services in.net (2)

Lampiran B. Program pengendali

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

Inheriting Windows Forms with Visual C#.NET

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

CALCULATOR APPLICATION

Operatii pop si push-stiva

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

Web Services in.net (7)

SMITE API Developer Guide TABLE OF CONTENTS

PS2 Random Walk Simulator

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

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

UNIT III APPLICATION DEVELOPMENT ON.NET

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

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)

UNIT-3. Prepared by R.VINODINI 1

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

Web Services in.net (6) cont d

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

Flag Quiz Application

Nasosoft Barcode for.net

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

.NET XML Web Services

Lucrare pentru colocviu de practică

Design-Time Integration

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

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

USB Logic Analyzer Shom Bandopadhaya Advisor: Dr. James H. Irwin

CSC 330 Object-Oriented Programming. Encapsulation

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

DotNetProcessing Documentation

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

IBSDK Quick Start Tutorial for C# 2010

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

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

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.

Towards More Comprehensive Information Retrieval Systems: Entity Extraction Using XSLT

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.

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

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

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

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

More Language Features and Windows Forms

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

CSIS 1624 CLASS TEST 6

Event-based Programming

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

Managed C++ and.net Development STEPHEN R. G. FRASER

Database Programming in Visual Basic.NET

Professional ASP.NET Web Services : Asynchronous Programming

Create a memory DC for double buffering

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values

CSC 211 Intermediate Programming

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

Web Services in.net (6)

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

The Payroll User Interface: MODEL VIEW PRESENTER

Chapter 12. Tool Strips, Status Strips, and Splitters

XNA 4.0 RPG Tutorials. Part 11b. Game Editors

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.

Visual Basic/C# Programming (330)

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

An array can hold values of any type. The entire collection shares a single name

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.

Conventions in this tutorial

Representing Recursive Relationships Using REP++ TreeView

Developing for Mobile Devices Lab (Part 1 of 2)

.NET and DB2 united with IBM DB2.NET Data Provider Objectives :.NET ADO.NET DB2 and ADO.NET DB2 - ADO.NET applications

Laboratorio di Ingegneria del Software

Laboratorio di Ingegneria del L-A

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

Using the Quinn-Curtis.Net Software (QCChart2D and QCRTGraph) with Managed C++ (MC++)

Form Properties Window

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

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

IDoc based adapterless communication between SAP NetWeaver Application Server (SAP NetWeaver AS) and Microsoft BizTalk Server

The Microsoft.NET Framework

Writing Your First Autodesk Revit Model Review Plug-In

Building non-windows applications (programs that only output to the command line and contain no GUI components).

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

Chapter 12 - Graphical User Interface Concepts: Part 1

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

Transcription:

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 without permission by the publisher). 1

User-Defined Controls Custom controls that inherit from other classes Ex: can change appearance of a label 2

GUI with user defined controls 3

Can edit the control s placeholder, but not the (inherited) control itself. 4

Running 5

Building the controls 6

Building the controls Dropped a standard Button in the new UserControl1 placeholder and adjusted its properties. 7

Building the controls Dropped 2 standard Buttons and adjusted their properties (and events). Dropped a standard Label and adjusted its properties. The userdefined control s placeholder. 8

Building the controls The resulting code components after building the controls. 9

Building the controls Once build the project, a.dll named WindowsControlLibrary1.dll is generated. This.DLL contains all the classes that correspond to the constructed controls. 10

To use any user defined controls Create new windows application. Then, from the toolbox, right-click and choose Add/Remove Items. 11

Select the desired controls The selected controls are made available in the Toolbox. You can use these controls to build any Windows Application, as usual. 12

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication10UsingUserDefinedControl / <summary> / Summary description for Form1. / </summary> public class Form1 : System.Windows.Forms.Form private WindowsControlLibrary1.UserControl1 usercontrol11; private WindowsControlLibrary1.UserControl1 usercontrol12; private WindowsControlLibrary1.UserControl2 usercontrol22; / <summary> / Required designer variable. / </summary> private System.ComponentModel.Container components = null; public Form1() Required for Windows Form Designer support InitializeComponent(); The code Form1.cs that uses user-defined controls Declare 2 blue buttons (UserControl1) and 1 timer (UserControl2). TODO: Add any constructor code after InitializeComponent call 13

Increase the default size of the placeholder of this blue button.. For one of the blue buttons, associate a click event on its placeholder. Keep the default size of the placeholder of this blue button. private void InitializeComponent() this.usercontrol11 = new WindowsControlLibrary1.UserControl1(); this.usercontrol12 = new WindowsControlLibrary1.UserControl1(); this.usercontrol22 = new WindowsControlLibrary1.UserControl2(); this.suspendlayout(); usercontrol11 this.usercontrol11.backcolor = System.Drawing.Color.DodgerBlue; this.usercontrol11.location = new System.Drawing.Point(16, 8); this.usercontrol11.name = "usercontrol11"; this.usercontrol11.size = new System.Drawing.Size(120, 80); this.usercontrol11.tabindex = 0; this.usercontrol11.click += new System.EventHandler(this.userControl11_Click); usercontrol12 this.usercontrol12.backcolor = System.Drawing.Color.DodgerBlue; this.usercontrol12.location = new System.Drawing.Point(192, 24); this.usercontrol12.name = "usercontrol12"; this.usercontrol12.size = new System.Drawing.Size(96, 48); this.usercontrol12.tabindex = 2; usercontrol22 this.usercontrol22.location = new System.Drawing.Point(48, 104); this.usercontrol22.name = "usercontrol22"; this.usercontrol22.size = new System.Drawing.Size(192, 104); this.usercontrol22.tabindex = 3; 14

Form1 this.autoscalebasesize = new System.Drawing.Size(5, 13); this.clientsize = new System.Drawing.Size(304, 229); this.controls.add(this.usercontrol22); this.controls.add(this.usercontrol12); this.controls.add(this.usercontrol11); this.name = "Form1"; this.text = "Form1"; this.resumelayout(false); / #endregion / <summary> / The main entry point for the application. / </summary> [STAThread] static void Main() Application.Run(new Form1()); private void usercontrol11_click(object sender, System.EventArgs e) MessageBox.Show("User control clicked"); Executes when user clicks on the placeholder of the control (but not on the blue button itself). 15

The code for UserControl1 (blue button) and UserControl2 (timer) 16

using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; namespace WindowsControlLibrary1 / <summary> / Summary description for UserControl1. / </summary> public class UserControl1 : System.Windows.Forms.UserControl private System.Windows.Forms.Button button1; / <summary> / Required designer variable. / </summary> private System.ComponentModel.Container components = null; UserControl1.cs public UserControl1() This call is required by the Windows.Forms Form Designer. InitializeComponent(); TODO: Add any initialization after the InitComponent call / <summary> / Clean up any resources being used. / </summary> User defined controls are made as subclasses of class UserControl. Put a button in this user defined control. 17

protected override void Dispose( bool disposing ) if( disposing ) if( components!= null ) components.dispose(); base.dispose( disposing ); #region Component Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> private void InitializeComponent() this.button1 = new System.Windows.Forms.Button(); this.suspendlayout(); button1 this.button1.font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.button1.forecolor = System.Drawing.Color.Black; this.button1.location = new System.Drawing.Point(0, 0); this.button1.name = "button1"; this.button1.size = new System.Drawing.Size(96, 48); this.button1.tabindex = 0; this.button1.text = "Blue Button"; this.button1.click += new System.EventHandler(this.button1_Click); 18

#endregion / UserControl1 this.backcolor = System.Drawing.Color.DodgerBlue; this.controls.add(this.button1); this.name = "UserControl1"; this.size = new System.Drawing.Size(96, 48); this.resumelayout(false); private void button1_click(object sender, System.EventArgs e) MessageBox.Show("Blue button clicked"); Executes when user clicks on the blue button within this control. 19

using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; UserControl2.cs (timer) namespace WindowsControlLibrary1 / <summary> / Summary description for UserControl2. / </summary> public class UserControl2 : System.Windows.Forms.UserControl private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.ComponentModel.IContainer components; Declare needed components that are included in this control. public UserControl2() This call is required by the Windows.Forms Form Designer. InitializeComponent(); TODO: Add any initialization after the InitializeComponent call / <summary> / Clean up any resources being used. / </summary> 20

protected override void Dispose( bool disposing ) if( disposing ) if(components!= null) components.dispose(); base.dispose( disposing ); #region Component Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / </summary> private void InitializeComponent() this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.suspendlayout(); timer1 this.timer1.tick += new System.EventHandler(this.timer1_Tick); label1 this.label1.backcolor = System.Drawing.Color.Yellow; this.label1.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.label1.location = new System.Drawing.Point(16, 48); this.label1.name = "label1"; this.label1.size = new System.Drawing.Size(168, 40); this.label1.tabindex = 0; this.label1.textalign = System.Drawing.ContentAlignment.MiddleCenter; 21

button1 this.button1.location = new System.Drawing.Point(16, 16); this.button1.name = "button1"; this.button1.tabindex = 1; this.button1.text = "Start Timer"; this.button1.click += new System.EventHandler(this.button1_Click); button2 this.button2.location = new System.Drawing.Point(104, 16); this.button2.name = "button2"; this.button2.tabindex = 2; this.button2.text = "Stop Timer"; this.button2.click += new System.EventHandler(this.button2_Click); UserControl2 this.controls.add(this.button2); this.controls.add(this.button1); this.controls.add(this.label1); this.name = "UserControl2"; this.size = new System.Drawing.Size(192, 104); this.resumelayout(false); #endregion 22

/ private void timer1_tick(object sender, System.EventArgs e) label1.text = DateTime.Now.ToLongTimeString(); private void button1_click(object sender, System.EventArgs e) timer1.start(); private void button2_click(object sender, System.EventArgs e) timer1.stop(); 23

C#.end 24