Ray Konopka Developing Custom.NET Components DevCon 2005 -- Course No: 3118.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
The GIMP Simple features tutorial By Mary A White.
1 USING FIREWORKS Cropping an Image Obtaining Information Changing Image Size Rotating an Image Adjusting the Color of an Image Drawing Tools Using the.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
User Interface Programming in C#: Graphics
Programming Based on Events
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Software Engineering1 The.NET Framework and the CLI 2D Graphics with GDI+ Visual Studio.NET 2008.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Creating a MagicInfo Pro Screen Template
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
IE 411/511: Visual Programming for Industrial Applications
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
CSC 298 Windows Forms.
Graphics and Multimedia Part #2
BIM211 – Visual Programming Objects, Collections, and Events 1.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
ASP.NET Web Server Controls Basic Web Server Controls.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
Ray Konopka Developing Custom.NET Component Designers DevCon Course No: 4106.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon Course No: 3146.
Ray Konopka Creating Custom Microsoft.NET Framework Controls in Delphi.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft PowerPoint 2002 Lesson 3 Developing.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
ASP.NET Forms.
OVERVIEW Objectives Follow a design document to prepare images for inclusion in a Web page Run a batch process to prepare multiple images in one step Use.
Graphics and Multimedia
Drawing Mouse and Keyboard Events Part A - Drawing
.NET and .NET Core 7. XAML Pan Wuming 2017.
C# Event Processing Model
CASE Tools Graphical User Interface Programming Using C#
Delegates & Events 1.
Project Design, Forms and Buttons
Web Development Using ASP .NET
Chapter 12 Graphics in Windows and the Web
Presentation transcript:

Ray Konopka Developing Custom.NET Components DevCon Course No: 3118

2 Agenda.NET Component Model Comparing the FCL to the VCL Custom Events Custom Painting Component Related Attributes Sample Control.NET Component Model Comparing the FCL to the VCL Custom Events Custom Painting Component Related Attributes Sample Control

3.NET Component Model Defined in the System.ComponentModel namespace Includes System.ComponentModel.Component declaration Common Delegates Component Related Attribute declarations Licensing Classes Design-time Support Classes Defined in the System.ComponentModel namespace Includes System.ComponentModel.Component declaration Common Delegates Component Related Attribute declarations Licensing Classes Design-time Support Classes

4 Component Class System.ComponentModel.Component provides the base implementation of IComponent in the FCL Defines the following properties DesignMode Container Site Events Descend from System.ComponentModel.Component to create a nonvisual component System.ComponentModel.Component provides the base implementation of IComponent in the FCL Defines the following properties DesignMode Container Site Events Descend from System.ComponentModel.Component to create a nonvisual component

5 Two Control Classes in.NET Most visual controls in.NET will descend from one of two classes: System.Windows.Forms.Control Base WinForms Control class Most similar to existing component models (e.g. VCL) Rendering handled through Graphics class (i.e. GDI+) System.Web.UI.Control Base ASP.NET Server Control class Renders markup text used by a client’s browser or viewing device to display visual elements. Most visual controls in.NET will descend from one of two classes: System.Windows.Forms.Control Base WinForms Control class Most similar to existing component models (e.g. VCL) Rendering handled through Graphics class (i.e. GDI+) System.Web.UI.Control Base ASP.NET Server Control class Renders markup text used by a client’s browser or viewing device to display visual elements.

6 System.Windows.Forms.Control Implements basic functionality for visualization Defines the control’s bounds (i.e. its Position and Size) Provides a window handle (Handle) Provides access to keyboard events Provides access to mouse events Provides access to paint events Supports ambient properties Cursor, Font, BackColor, ForeColor, RightToLeft. Implements basic functionality for visualization Defines the control’s bounds (i.e. its Position and Size) Provides a window handle (Handle) Provides access to keyboard events Provides access to mouse events Provides access to paint events Supports ambient properties Cursor, Font, BackColor, ForeColor, RightToLeft.

7 Comparing the FCL to the VCL FCL is quite similar to the VCL, but there are significant differences No equivalent to TGraphicControl Actually, no TWinControl or TCustomControl classes either System.Windows.Forms.Control is more like TCustomControl than TControl Significantly fewer TCustomXxxx class called XxxxBase in FCL FCL is quite similar to the VCL, but there are significant differences No equivalent to TGraphicControl Actually, no TWinControl or TCustomControl classes either System.Windows.Forms.Control is more like TCustomControl than TControl Significantly fewer TCustomXxxx class called XxxxBase in FCL

8 Where is the Align property? Most of the functionality implemented in the VCL base classes is available in the base FCL classes However, there are many property name changes Align  Dock Caption  Text Color  BackColor Font.Color  ForeColor PopupMenu  ContextMenu ModalResult  DialogResult etc. Tag is an Object ParentXxxx properties replaced with ambient properties Most of the functionality implemented in the VCL base classes is available in the base FCL classes However, there are many property name changes Align  Dock Caption  Text Color  BackColor Font.Color  ForeColor PopupMenu  ContextMenu ModalResult  DialogResult etc. Tag is an Object ParentXxxx properties replaced with ambient properties

9 Control Styles TControl.ControlStyle replaced with GetStyle/SetStyle method pair Some, but not all, styles have corresponding public properties ResizeRedraw TControl.ControlStyle replaced with GetStyle/SetStyle method pair Some, but not all, styles have corresponding public properties ResizeRedraw SetStyle( ControlStyles.ResizeRedraw, True ); SetStyle( ControlStyles.Opaque, True ); // Double Buffering SetStyle( ControlStyles.UserPaint, True ); SetStyle( ControlStyles.AllPaintingInWmPaint, True ); SetStyle( ControlStyles.DoubleBuffer, True ); SetStyle( ControlStyles.ResizeRedraw, True ); SetStyle( ControlStyles.Opaque, True ); // Double Buffering SetStyle( ControlStyles.UserPaint, True ); SetStyle( ControlStyles.AllPaintingInWmPaint, True ); SetStyle( ControlStyles.DoubleBuffer, True );

10 Component Notifications Component notifications allow descendants to react to state changes implemented in an ancestor class In the VCL, a component responds to notifications by handling special messages e.g. cm_EnabledChanged In.NET, a component responds to notifications by overriding a method OnEnabledChanged Event Dispatch Method.NET even surfaces component notifications as public events EnabledChanged Event Component notifications allow descendants to react to state changes implemented in an ancestor class In the VCL, a component responds to notifications by handling special messages e.g. cm_EnabledChanged In.NET, a component responds to notifications by overriding a method OnEnabledChanged Event Dispatch Method.NET even surfaces component notifications as public events EnabledChanged Event

11 FCL and VCL Events Unfortunately, the naming convention used for events in the FCL is opposite that used in the VCL In the VCL… OnPaint is the event Paint is the event dispatch method In the FCL… OnPaint is the event dispatch method Paint is the event Unfortunately, the naming convention used for events in the FCL is opposite that used in the VCL In the VCL… OnPaint is the event Paint is the event dispatch method In the FCL… OnPaint is the event dispatch method Paint is the event

12 FCL and VCL Events Please Note: Unfortunately, it is common in.NET literature to see statements like  “…take a look at the OnPaint event handler…” Problem is that base (ancestor) does not get called and thus the real event never gets raised Please Note: Unfortunately, it is common in.NET literature to see statements like  “…take a look at the OnPaint event handler…” Problem is that base (ancestor) does not get called and thus the real event never gets raised

13 Events Events allow customization through delegation Events are properties Implemented using Delegates Events are optional Events allow customization through delegation Events are properties Implemented using Delegates Events are optional

14 Creating a Custom Event Determine the action that triggers event Define the event type (i.e. the Delegate) Specifies the parameters that will be sent to an event handler Declare the event property Singleton Event (read/write) Multicast Event (add/remove) Dispatch the event when it occurs. Determine the action that triggers event Define the event type (i.e. the Delegate) Specifies the parameters that will be sent to an event handler Declare the event property Singleton Event (read/write) Multicast Event (add/remove) Dispatch the event when it occurs.

15 Determine Event Trigger Events allow developers to “hook” into normal processing Example Generate a ValueChanged event when data represented by the component changes Events allow developers to “hook” into normal processing Example Generate a ValueChanged event when data represented by the component changes

16 Delegates The FCL utilizes Delegates to support events A delegate is a class that encapsulates a linked-list of method pointers With delegates an event can be sent to multiple subscribers Specify the parameters that will be sent to event handlers. The FCL utilizes Delegates to support events A delegate is a class that encapsulates a linked-list of method pointers With delegates an event can be sent to multiple subscribers Specify the parameters that will be sent to event handlers.

17 Define the Delegate May be possible to use predefined delegate e.g. EventHandler First parameter always “object sender” Second parameter always EventArgs or descendant If you require passing additional parameters, you’ll need to create a new EventArgs descendant May be possible to use predefined delegate e.g. EventHandler First parameter always “object sender” Second parameter always EventArgs or descendant If you require passing additional parameters, you’ll need to create a new EventArgs descendant ValueChangingEventHandler = procedure ( sender: System.Object; e: ValueChangingEventArgs ) of object; ValueChangingEventHandler = procedure ( sender: System.Object; e: ValueChangingEventArgs ) of object;

18 Case Sensitivity in Delphi? Delphi is not case sensitive, but other.NET languages are (namely C#) Event handler signature is exported in case sensitive In C#, parameters are lower case As such, recommended to use and not Delphi is not case sensitive, but other.NET languages are (namely C#) Event handler signature is exported in case sensitive In C#, parameters are lower case As such, recommended to use and not ValueChangingEventHandler = procedure ( Sender: System.Object; E: ValueChangingEventArgs ) of object; ValueChangingEventHandler = procedure ( Sender: System.Object; E: ValueChangingEventArgs ) of object; ValueChangingEventHandler = procedure ( sender: System.Object; e: ValueChangingEventArgs ) of object; ValueChangingEventHandler = procedure ( sender: System.Object; e: ValueChangingEventArgs ) of object;

19 Declare the Event Property Unlike the VCL, by convention event names in the FCL do not start with “On” // Multicast Event property ValueChanged: EventHandler add FValueChanged remove FValueChanged; // Singleton Event property ValueChanging: ValueChangingEventHandler read FValueChanging write FValueChanging; // Multicast Event property ValueChanged: EventHandler add FValueChanged remove FValueChanged; // Singleton Event property ValueChanging: ValueChangingEventHandler read FValueChanging write FValueChanging;

20 Raise the Event Use an Event Dispatch Method In FCL, event dispatch methods start with “On” Usually defined as strict protected and virtual Calling the event (e.g. FValueChanged) causes all of the event handlers in the delegate’s list to be called Use an Event Dispatch Method In FCL, event dispatch methods start with “On” Usually defined as strict protected and virtual Calling the event (e.g. FValueChanged) causes all of the event handlers in the delegate’s list to be called procedure RkSpinner.OnValueChanged( e: EventArgs ); begin if Assigned( FValueChanged ) then FValueChanged( Self, e ); end; procedure RkSpinner.OnValueChanged( e: EventArgs ); begin if Assigned( FValueChanged ) then FValueChanged( Self, e ); end;

21 Custom Painting Custom painting supported by Graphics class (GDI+) System.Drawing System.Drawing.Drawing2D System.Drawing.Imaging System.Drawing.Text GDI+ Features Alpha Blending & Anti-Aliased 2D Drawing Gradient Brushes Universal Transformations & FP coordinates Support for more Image formats  BMP, GIF, JPEG, PNG, TIFF, ICON, WMF, EMF. Custom painting supported by Graphics class (GDI+) System.Drawing System.Drawing.Drawing2D System.Drawing.Imaging System.Drawing.Text GDI+ Features Alpha Blending & Anti-Aliased 2D Drawing Gradient Brushes Universal Transformations & FP coordinates Support for more Image formats  BMP, GIF, JPEG, PNG, TIFF, ICON, WMF, EMF.

22 GDI+ Programming Model No more device contexts (DC) – Graphics Object GDI+ is Stateless No more selecting pens and brushes into a DC Pens, Brushes, etc. are passed to each GDI+ drawing method Graphic elements are no longer drawn with both Pen and Brush Draw methods use a Pen (eg. DrawRectangle) Fill methods use a Brush (eg. FillEllipse). No more device contexts (DC) – Graphics Object GDI+ is Stateless No more selecting pens and brushes into a DC Pens, Brushes, etc. are passed to each GDI+ drawing method Graphic elements are no longer drawn with both Pen and Brush Draw methods use a Pen (eg. DrawRectangle) Fill methods use a Brush (eg. FillEllipse).

23 GDI+ Programming Model Colors support Alpha Channels ARGB format  0x880000FF semi-transparent blue A = 0x00 fully transparent A = 0xFF fully opaque Rectangles, Points, etc. are classes r.Inflate( 5, 5 ); // Instead of InflateRect( r, 5, 5 ); Rectangles are defined differently! Left, Top, Width, Height. Colors support Alpha Channels ARGB format  0x880000FF semi-transparent blue A = 0x00 fully transparent A = 0xFF fully opaque Rectangles, Points, etc. are classes r.Inflate( 5, 5 ); // Instead of InflateRect( r, 5, 5 ); Rectangles are defined differently! Left, Top, Width, Height.

24 GDI+ Programming Model Obtaining a Graphics Object Passed to OnPaint methods in PaintEventArgs Request one using Graphics.FromHwnd( Handle ) If utilizing double-buffering, do not use FromHwnd Cleaning Up Dispose all GDI+ objects Dispose Graphics object if requested via FromHwnd Obtaining a Graphics Object Passed to OnPaint methods in PaintEventArgs Request one using Graphics.FromHwnd( Handle ) If utilizing double-buffering, do not use FromHwnd Cleaning Up Dispose all GDI+ objects Dispose Graphics object if requested via FromHwnd

25 Attributes Attributes used to modify the behavior of properties, methods, events [ Category( 'Appearance' ) ] [ Description( 'The width of buttons, in pixels.' ) ] [ DefaultValue( 18 ) ] property ButtonWidth: Integer read FButtonWidth write SetButtonWidth; // No Category or Description, but DefaultValue property ButtonHeight: Integer read FButtonHeight write SetButtonHeight default 18; [ Category( 'Appearance' ) ] [ Description( 'The width of buttons, in pixels.' ) ] [ DefaultValue( 18 ) ] property ButtonWidth: Integer read FButtonWidth write SetButtonWidth; // No Category or Description, but DefaultValue property ButtonHeight: Integer read FButtonHeight write SetButtonHeight default 18;

26 Attributes Category Description Browsable DefaultValue DefaultProperty & DefaultEvent Localizable ToolboxBitmap Category Description Browsable DefaultValue DefaultProperty & DefaultEvent Localizable ToolboxBitmap

27 Example RayKonopka.Delphi.Controls Assembly RkSpinner Component RayKonopka.Delphi.Controls Assembly RkSpinner Component

28 The Finish Line Contact Information Evaluation Forms Questions & Answers Contact Information Evaluation Forms Questions & Answers Ray Konopka Ray Konopka