ebook img

GDI+ Custom Controls With Visual C# 2005 PDF

271 Pages·2006·6.297 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview GDI+ Custom Controls With Visual C# 2005

wG i t hD V I is+ u GDI+ Custom Controls with a C l C u # Visual C# 2005 2s 0t 0 o 5 m If you want to build custom controls with C# but you don’t know where to start, or you are C intimidated by the huge amount of information that needs to be absorbed, then this book is for o you. This friendly tutorial is based on numerous examples with real-world applicability, and includes n a case study featuring the development of a fully functional PieChart control. t r Showing you how to use the free Visual C# 2005 Express Edition environment to develop your o controls, Building Custom Controls with Visual C# 2005 will teach you how to create professional, l s reusable custom controls for your desktop applications in no time. What you will learn from this book • Understand the basics of custom controls • Use GDI+ to draw your own controls • Implement double buffering to speed up your forms F r o m T e c h n o l o g i e s t o S o l u t i o n s • Add printing functionality to your custom controls TI • Handle the mouse events to improve the user experience ibeulia • Offer design-time support for programmers using your control riun S GDI+ Custom Controls • Design intuitive interfaces for your users Re arb da un WTknhohiswo ble otdohgkie sh o abfs oC bo#e,ke tn hi esw brwiottoeriknt ttweeianthc hftheoesr yinotue rhmoewd itaot eim Cp#le dmeevnetl ocpuesrt oinm m cionndt.r oAlsss uusminingg V ais wuaolr kCin#g 2 005 A D with Visual C# 2005 Express Edition, and GDI+. dr aa mg o Ws aB A fast-paced example-driven tutorial to building custom rdre z o controls using Visual C# 2005 Express Edition and .NET 2.0 i $ 34.99 US Packt Publishing £ 22.99 UK Birmingham - Mumbai € 32.99 EU www.packtpub.com Prices do not include local sales tax or VAT Iulian Serban Dragos Brezoi where applicable Tiberiu Radu Adam Ward GDI+ Custom Controls with Visual C# 2005 A fast-paced example-driven tutorial to building custom controls using Visual C# 2005 Express Edition and .NET 2.0 Iulian Serban Dragos Brezoi Tiberiu Radu Adam Ward BIRMINGHAM - MUMBAI GDI+ Custom Controls with Visual C# 2005 Copyright © 2006 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: July 2006 Production Reference: 1220706 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 1-904811-60-4 www.packtpub.com Cover Image by www.visionwt.com Credits Authors Development Editor Iulian Serban Cristian Darie Dragos Brezoi Tiberiu Radu Indexer Adam Ward Niranjan Jahagirdar Reviewer Proofreader Cosmin Oprea Chris Smith Technical Editor Layouts and Illustrations Mithil Kulkarni Shantanu Zagade Editorial Manager Cover Designer Dipali Chittar Shantanu Zagade About the Authors Iulian Serban is a software architect who started programming at a very young age. He evolved through a lot of programming languages including Pascal, Delphi, C++ Builder, Visual C++ with MFC and finally .NET and C #. By the age of 17 he started working for Syncfusion, one of the largest .NET control builders in the US, writing code for professional custom controls. Nowadays he devotes most of his spare time to his own IT business, which is set to release significant software projects soon. I'm using this opportunity to thank the Syncfusion team for their continued support, and for their professionalism. Dragos Brezoi started programming to create an application for processing and adding extra effects to his guitar's sound. Several years after, he got a Masters Degree in Computer Science from the Politehnica University of Bucharest, and is now researching for a Ph.D. in Advanced Automatics. Dragos currently works as a programmer for Mikon Systems, developing industrial software. His skills cover a wide area of specialization from PLC and DSP programming to SCADA, OPC, and DCS solutions. At this moment he is creating professional human-machine interfaces, with a focus on developing advanced custom controls with C#. My big thanks go to my son, Matei, who was a wonderful and cooperative baby and let me work on this book. Tiberiu Radu has been working with computers for over 10 years now, programming in a wide range of languages including Pascal, C/C++, Visual Basic, Delphi, and C#. As a Microsoft Student Partner in the Microsoft Academic Program, he's devoting a lot of time to many .NET-related technologies. Tiberiu is in the last year of studies with the Automatic Control and Computers Faculty of the Politehnica University of Bucharest. While researching for his own IT security business, he developed skills in embedded programming and new web technologies, and is seeking new and innovating networking security solutions. Adam Ward works for a communications technology company in Derby, England. Adam excels in experimental programming techniques and has a particular interest in high-speed algorithms and graphical methods. His professional work is based in a varied Research and Development environment and he thrives on tasks requiring innovation, skill, and fine-tuning. He has also been involved in experimental coding collaborations showcasing the power of C#. Away from work, Adam is turning his attentions to Linux systems and especially cross-platform programming under .NET-compatible systems. About the Reviewer Cosmin Oprea is a veteran in the software industry, having written code in languages ranging from C/C++ to VB6 and C#. His experience with GDI started when working with the Win32 API on Windows 95, and nowadays he's using GDI+ to give a final touch and better look and feel to his Windows Forms interfaces. Cosmin is a big fan of agile methodologies (such as Extreme Programming), which he has successfully applied when developing various enterprise-class applications based on .NET technologies. Microsoft Romania has recently awarded Cosmin in recognition of his influence as a .NET evangelist, and for his contribution to the Romanian .NET User Association (RONUA). Table of Contents Preface 1 Chapter 1: Introduction to Custom Controls 5 What Are Controls? 5 Introducing Custom Controls 7 Categories of User Controls 9 Preparing Your Environment 9 What Are Custom Controls Made Of? 9 Private Fields 10 Properties 11 Indexers 13 Events and Delegates 14 Handling Events 16 Collections 17 Enums 19 Building TinyNoiseMaker 20 Time for Action—Creating the TinyNoiseMaker Custom Control 20 Extending TinyNoiseMaker 27 Time for Action—Adding Public Functionality 27 Time for Action—Using the Control's Public Interface 31 Summary 33 Chapter 2: Introduction to GDI+ 35 Understanding Control Drawing 35 Understanding GDI+ 36 The Graphics Object 36 The Control.Paint Event 37 Invalidation 37 Simple Drawing on a Form 38 Time for Action—Creating the Application 38 Drawing Inside a Panel Object 41 Time for Action—Creating the Application 41 Table of Contents Drawing Inside a Control 42 Time for Action—Creating the Application 43 Summary 45 Chapter 3: Basic Drawing 47 The GDI+ Coordinate System 47 Drawing with GDI+ 49 Using the Color Object 49 Drawing Using the Pen Object 50 Filling Surfaces Using the Brush Object 51 Drawing Text Using the Font Object 52 Improving Drawing Quality 53 Building the GradientLabel Control 54 Time for Action—Creating the GradientLabel Custom Control 54 Summary 56 Chapter 4: Drawing Complex Shapes and Using Transformations 57 Drawing Complex Shapes 57 The GraphicsPath Object 58 The Region Object 62 Clipping Drawing Using Region Objects 65 Keeping Drawing Inside a Region 65 Keeping Drawing Outside a Region 66 Graphics Transformations 67 Translation 68 Rotation 69 Scaling 70 Creating the Clock Control 71 Time for Action—Creating the Clock Control 71 Time for Action—Updating the Clock to Use Transformations 77 Summary 78 Chapter 5: Drawing Control Parts, Borders, and Adornments 79 Rendering Common Control Parts 79 Drawing Buttons 80 Drawing Caption Buttons 81 Drawing Checkboxes 82 ii Table of Contents Drawing Drop-Down Buttons 83 Drawing Radio Buttons 83 Drawing Scroll Buttons 84 Rendering Borders and Frames 85 Rendering Button Borders 85 Rendering 3D Borders 86 Rendering Control Adornments 87 Creating Multiple Controls that Reuse the Same Functionality 88 Creating a Base Class for Two or More Controls 89 Time for Action—Creating the ControlPart Base Class 89 Creating Derived Controls 91 Time for Action—Creating the ScrollArrowButton Control 91 Time for Action—Creating the CheckButton Control 93 Extending Existing Controls 94 Time for Action—Creating the BorderGradientPanel Control 94 Time for Action—Implementing the GradientButton Control 96 Summary 98 Chapter 6: Working with Images 99 Drawing Images 100 Using the Image Class 100 Using the Bitmap Class 101 Displaying Images 103 Time for Action—Displaying Images 103 Image Effects 105 Skewing, Rotation, and Scaling 107 Building the ImageWarper Class 108 Time for Action—Creating the ImageWarper Class 109 The ImageWarperControl 113 Time for Action—Creating the ImageWarperApp and the Image WarperControl 113 Summary 120 Chapter 7: Printing 121 .NET Printing Explained 121 Using the PrintDocument Class 122 Your First Print Job 123 Time for Action—Creating the "Hello Printer!" Application 123 iii Table of Contents The SimpleReportPrinter 126 Building the SimpleReportPrinter and TextDispenser Classes 126 Time for Action—Building the TextDispenser Class 128 Time for Action—Building the SimpleReportPrinter Class 130 User Involvement 134 Our Responsibilities as Programmers 137 Printing Custom Controls 137 Time for Action—Creating the PrintableRichTextBox 138 Summary 141 Chapter 8: Collections 143 Collections in the .NET Framework 144 ArrayList 144 Queue 145 Stack 146 SortedList 148 Generics 150 Building the Font Picker 152 Time for Action—Building Font Picker 152 Summary 163 Chapter 9: Double Buffering 165 Introduction to Double Buffering 165 The Scroll Bar 166 Scroll that Text! 168 Time for Action—Building FlickerFree Control 169 Summary 175 Chapter 10: Handling Mouse Events 177 Handling Mouse Events 178 Working with Coordinates 179 Dragging and Dropping 179 Dragging 180 Time for Action—Dragging 181 Dragging and Dropping 188 Time for Action—Dragging and Dropping 188 Summary 193 iv

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.