Component Programming with C# and.NET. C# components The most commonly used components in.NET are the visual controls that you add to Windows Forms such.

Slides:



Advertisements
Similar presentations
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Advertisements

11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
The Web Warrior Guide to Web Design Technologies
Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
AP 08/01 Component Programming with C# and.NET 1st Class Component Support Robust and Versionable Creating and using attributes API integration –DLL import.
Getting Started with VB .NET
Advanced Object-Oriented Programming Features
1/50 Project Management. 2/50 StumbleUpon 3/50 Overview Customize? Why, what, how?.NET Framework overview & fundamentals Class libraries, namespaces,
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.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Getting Started Example ICS2O curriculum
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Visual Basic Chapter 1 Mr. Wangler.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Component-Based Software Engineering Component process.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
Prepared by: Sanaz Helmi Hoda Akbari Zahra Ahmadi Sharif University of Tech. Summer 2006 An Introduction to.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
OCC Network Drives  H:\  P:\ 
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Introduction to ASP.NET T.Ahlam Algharasi. The Visual Studio IDE Start page 2.
ILM Proprietary and Confidential -
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.
Module 1: Getting Started. Introduction to.NET and the.NET Framework Exploring Visual Studio.NET Creating a Windows Application Project Overview Use Visual.
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
Attributes C#.Net Software Development Version 1.0.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Classes Single inheritance Single inheritance Multiple interface implementation Multiple interface implementation Class members Class members  Constants,
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Problem: Take Two Numbers, Add Them Together And Display The Results. Now To Build The Flowchart… We Probably Need One Like This… Let’s Add The Routines…
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
The 100% Inspiration Tour.
.NET and .NET Core 10. Enabling Contracts Pan Wuming 2017.
How to organize and document your classes
Presentation transcript:

Component Programming with C# and.NET

C# components The most commonly used components in.NET are the visual controls that you add to Windows Forms such as the Button Control (Windows Forms), ComboBox Control (Windows Forms), and so on.Button Control (Windows Forms)ComboBox Control (Windows Forms) Non-visual components include the Timer Control, SerialPort, and ServiceController among others.Timer ControlSerialPortServiceController

What defines a component? – Properties, methods, events – Design-time and runtime information – Integrated help and documentation

AP 08/01 public class Button: Control { private string caption; private string caption; public string Caption { public string Caption { get { get { return caption; return caption; } set { set { caption = value; caption = value; Repaint(); Repaint(); } }} Properties Properties are “smart fields” – Natural syntax, accessors, inlining Button b = new Button(); b.Caption = "OK"; String s = b.Caption;

AP 08/01 Indexers Indexers are “smart arrays” – Can be overloaded public class ListBox: Control { private string[] items; public string this[int index]{ get { return items[index]; } set { items[index] = value; Repaint(); } ListBox listBox = new ListBox(); listBox[0] = "hello"; Console.WriteLine(listBox[0]);

AP 08/01 Events Efficient, type-safe and customizable – Built on delegates public class MyForm: Form { public MyForm() { Button okButton = new Button(...); okButton.Click += new EventHandler(OkButtonClick); } void OkButtonClick(…) { ShowMessage("You clicked OK"); }

Events Events enable a class or object to notify other classes or objects when something of interest occursclass The class that sends (or raises) the event is called the publisherand the classes that receive (or handle) the event are called subscribers.

Example Arithmetic component which does addition We will create a component called csAddComp1 and package it into a dll (Dynamic Linked Library). This component has two properties and a method. Properties take input for the addition and method called Sum( ).

Example To create properties in C# you use the get and set accessors. The get accessor is used for getting (reading). The set accessor for setting (writing) the property

Component Program using System; namespace CompCS { public class csAddComp1 { private int i=0,j=0; public int varI { get { return i; } //this is property get for varI set { i=value; } //this is property set for varI } public int varJ { get { return j; } // this is property get for varJ set { j=value; } // this is property set for varJ } public int Sum() { return i+j; //this returns the sum of two variables } } //end of class } //end of namespace

DLL package To package the component as dll there is slight change in usual compilation process. Its little complicated process when compared to normal stand-alone program compilation. csc /out:csAddComp1.dll /target:library csAddComp1.cs Here the /out switch to put the compiled component in the relative subdirectory and file for convenience. Likewise, we need the /target:library switch to actually create a DLL rather than an executable with a.dll file extension.

client program using System; using CompCS; class clAddComp1 { public static void Main() { csAddComp1 addComp= new csAddComp1(); addComp.varI=10; //property set for varI addComp.varJ=20; //property set for varJ //below property get for varI Console.WriteLine("variable I value : {0}",addComp.varI); //below property get for varJ Console.WriteLine("variable J value : {0}",addComp.varJ); // calling Sum(..) method Console.WriteLine("The Sum : {0}",addComp.Sum()); } //end of Main } // end of Class

Component Designer in C# Allows to add subcomponents to a class, configure them, and code their events. Add components and items from the Toolbox or from Server Explorer. Group together a set of subcomponents into a single class. Double-click the designer and write code in the general declarations section of the class, or double- click an element on the designer to write code for that element.

Component Designer in C# To display the designer, from the Project menu, select Add Component. The Add New Item dialog box appears. By default, the Component Class item is selected. Click OK to add a new component to project and open the Component Designer.

As an example, to package the alarm functionality we built earlier around the Timer component, let's build anAlarmComponent class. To create a new component class, right-click on the project and choose Add | Add Component, enter the name of your component class, and press OK. You'll be greeted with a blank design surface,

using System; using System.ComponentModel; using System.Collections; using System.Diagnostics; namespace Components { public class AlarmComponent : System.ComponentModel.Component { private Timer timer1; private System.ComponentModel.IContainer components; public AlarmComponent(System.ComponentModel.IContainer container) { container.Add(this); InitializeComponent(); } public AlarmComponent() { InitializeComponent(); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1.Enabled = true; }}}

Attributes C# declarations contain keywords, such as public and private, that provide additional information about class members. These keywords further define the behavior of class members by describing their accessibility to other classes. Because compilers are explicitly designed to recognize predefined keywords, you do not traditionally have the opportunity to create your own. keyword-like descriptive declarations, called attributes, annotate programming elements such as types, fields, methods, and properties.

Attributes How do you associate information with types and members? – Documentation URL for a class – Transaction context for a method – XML persistence mapping Traditional solutions – Add keywords or pragmas to language – Use external files, e.g.,.IDL,.DEF C# solution: Attributes

Attributes We can use attributes to define both design-level information (such as help file, URL for documentation) and run-time information (such as associating XML field with class field). We can also create "self-describing" components using attributes.

Attributes [HelpUrl(“ class SomeClass { [WebMethod] [WebMethod] void GetCustomers() { … } void GetCustomers() { … } string Test([SomeAttr] string param1) {…} string Test([SomeAttr] string param1) {…}} Appear in square brackets Attached to code elements

Apply attributes Define a new attribute or use an existing attribute by importing its namespace from the.NET Framework.

Example using System; public class AnyClass { [Obsolete("Don't use Old method, use New method", true)] static void Old( ) { } static void New( ) { } public static void Main( ) { Old( ); }

Example we use attribute Obsolete, which marks a program entity that should not be used. The first parameter is the string that can be any text. The second parameter tells the compiler to treat the use of the item as an error. Default value is false, which means compiler generates a warning for this.

Attribute Fundamentals Attributes are classes! Completely generic class HelpUrl : System.Attribute { public HelpUrl(string url) { … } … } [HelpUrl(“ class SomeClass { … }

Attributes to specify DLL Imports [DllImport("gdi32.dll",CharSet=CharSet.Auto)] public static extern int GetObject( int hObject, int nSize, [In, Out] ref LOGFONT lf); [DllImport("gdi32.dll")] public static extern int CreatePen(int style, int width, int color);

Component & attributes components can be displayed in a designer, such as Visual Studio.NET, but required attributes that provide metadata to design-time tools. A DesignerAttribute attribute is applied at the class level and informs the forms designer which designer class to use to display the control. Components are associated with a default designer (System.ComponentModel.Design.ComponentDesigner), and Windows Forms and ASP.NET server controls are associated with their own default designers. Apply DesignerAttribute only if you define a custom designer for your component or control.

To add a security attribute to a code member of your component using System.Security.Permissions; [FileIOPermission(SecurityAction.Demand)] public void FileDeleter() { // Insert code to delete files. }

COM Support.NET Framework provides great COM support – TLBIMP imports existing COM classes – TLBEXP exports.NET types Most users will have a seamless experience

Building COM components using.NET Framework Create C# - Class Library project Configure Project Property Pages with the right information Develop the AccountManager.cs library Modify the generated AssemblyInfo.cs to add the right assembly information Build the Project Files Deploy the component as a Shared Assembly, and Configure the Assembly in the COM+ Catalog

Configure your Project Property Pages with the right information

add the right assembly information [assembly: AssemblyTitle("AccountManager for Bank")] [assembly: AssemblyDescription("Creates and Deletes Accounts for the Bank")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("eCommWare Corporation")] [assembly: AssemblyProduct("COM+ Bank Server")] [assembly: AssemblyCopyright("(c) 2001, Gopalan Suresh Raj. All Rights Reserved.")] [assembly: AssemblyTrademark("Web Cornucopia")] [assembly: AssemblyCulture("en-US")]

Calling into a COM component Create.NET assembly from COM component via tlbimp Client apps may access the newly created assembly using System; using System.Runtime.InteropServices; using CONVERTERLib; class Convert { public static void Main(string [] args) { CFConvert conv = new CFConvert();... fahrenheit = conv.CelsiusToFahrenheit( celsius );