Windows Forms in Action Windows Forms in Action Second Edition of Windows Forms Programming with C# ERIK BROWN MANNING Greenwich (74° w. long.) For online information and ordering of this and other Manning books, go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 209 Bruce Park Avenue Fax: (203) 661-9018 Greenwich, CT 06830 email: [email protected] ©2006 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Liz Welch 209 Bruce Park Avenue Typesetter: Dottie Marsico Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1932394-65-6 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – VHG – 10 09 08 07 06 In memory of Thelma Rose Wilson, and for her beautiful daughter, whom I still love brief contents Part 1 Hello Windows Forms 1 1 Getting started with Windows Forms 3 2 Getting started with Visual Studio 33 Part 2 Basic Windows Forms 63 3 Menus 67 4 Context menu and status strips 92 5 Reusable libraries 116 6 Files and common dialog boxes 148 7 Dialog boxes 180 8 Text boxes 212 9 Buttons 240 10 Handling user input and encryption 268 11 List boxes 299 12 Combo boxes 327 13 Tab controls and pages 356 14 Dates, calendars, and progress bars 383 15 Bells and whistles 415 16 Tool strips 443 vii Part 3 Advanced Windows Forms 475 17 Custom controls 477 18 Explorer interfaces and tree views 507 19 List views 541 20 Multiple document interfaces 575 21 Data binding 608 22 Two-way binding and binding sources 637 23 Odds and ends .NET 665 appendix A C# primer 701 appendix B .NET namespaces 735 appendix C Visual index 741 appendix D For more information 758 viii contents preface xix preface to the first edition xxi acknowledgments xxiii about this book xxv what’s new in 2.0 xxxiii about the cover illustration xxxv Part 1 Hello Windows Forms 1 1 Getting started with Windows Forms 3 1.1 Programming in C# 4 Namespaces and classes 6 ✦ Constructors and methods 8 C# types 8 ✦ The Main method 11 ✦ The Application class 12 ✦ Program execution 13 1.2 Windows Forms controls 14 The using directive 15 ✦ The Control class 17 The Controls property 18 1.3 Loading files 19 Events 21 ✦ The OpenFileDialog class 23 ✦ Bitmap images 26 1.4 Resizing forms 26 The Anchor property 29 ✦ The Dock property 30 1.5 Recap 32 2 Getting started with Visual Studio 33 2.1 Programming with Visual Studio 34 Creating a project 35 ✦ Executing a program 37 Viewing the source code 38 ix
Description: