DEV393.NET Windows Forms Tips and Tricks Ken Getz Senior Consultant MCW Technologies, LLC.

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2006 Windows Presentation Foundation (WPF) Marcus Perryman
Advertisements

DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation. All.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Windows Forms in Visual Studio 2005: An in-depth look at key features Name: Mike Henderlight Title: Program Manager.
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
1 of 4 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
Chapter 13: Advanced GUI and Graphics
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2006 Microsoft Corporation.
1/26/2004 PPCC - Introduction to VB6 Copyright ©2004, Tore Bostrup 1 Introduction to VB6 Materials & Prerequisites Course Outline Background Information.
OFC324 Microsoft Project Server: Putting Enterprise Project Management (EPM) To Work Sam Brooks
Microsoft Office Word 2013 Expert Microsoft Office Word 2013 Expert Courseware # 3251 Lesson 4: Working with Forms.
DAT304 Leveraging XML and HTTP with Sql Server Irwin Dolobowsky Program Manager Webdata Group.
MS Access Advanced Instructor: Vicki Weidler Assistant:
DEV317 Integrating Extensible Business Graphics into Enterprise Applications using Visio 2003 Mai-lan Tomsen Bukovec Program Manager.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
OFC 322 Building Office Research Web Services: Exposing Corporate Data Through Office Brian Jones Program Manager Authoring Services Martin Sawicki Lead.
1 Programming Concepts Module Code : CMV6107 Class Contact Hours: 45 hours (Lecture 15 hours) (Laboratory/Tutorial 30 hours) Module Value: 1 Textbook:
DEV334 Creating Application Starting Points & Sharing Best Practices with Enterprise Templates Marc Gusmano Director of Emerging Technologies The Information.
Databases and LINQ Visual Basic 2010 How to Program 1.
OFC304 Excel 2003 Overview: XML Support Joseph Chirilov Program Manager.
DEV390 Extending Word and Excel with Visual Studio Tools for Office Ken Getz Senior Consultant MCW Technologies, LLC.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Using the Actions Pane, Host Controls, and Smart Tags
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
DEV290 Building Office Solutions with Visual Studio Eric Carter Lead Developer Developer Platform & Evangelism Microsoft Corporation.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
DEV397 Windows Forms Databinding Mike Henderlight Program Manager Windows Forms Microsoft Corporation.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Developing Reporting Solutions with SQL Server
WEB 304 An Overview of ASP.NET and Windows Workflow Foundation Kashif Alam Program Manager Developer Division Microsoft Corporation.
DEV402 Extending the ASP.NET Runtime Jurgen Postelmans Microsoft Regional Director BeLux U2U.
DAT305 Boost Your Data-Driven Application Development Using SQL Server Centric.NET Code Generator Pascal Belaud Microsoft France.
DAT235 Authoring Reports Using SQL Server 2000 Reporting Services Brian Welcker Group Program Manager SQL Server Business Intelligence Microsoft Corporation.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
Windows Forms: Harnessing The Power And Flexibility Of Windows Forms 2.0 Erick Ellis PRS402 Program Manager.NET Client Microsoft Corporation.
DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design
DEV305 Presenting Data with the ASP.NET DataGrid Control Ken Getz Senior Consultant MCW Technologies, LLC.
Slide 1.NET Development for Project 2003 Samples from the Project 2003 SDK Jim Corbin Programmer Writer Office Developer Documentation Microsoft Corporation.
CHAPTER TWO INTRODUCTION TO VISUAL BASIC © Prepared By: Razif Razali 1.
DEV384 COM+ Lives : New Features in Enterprise Services Included in Windows Server 2003 Catherine Heller Senior Consultant Microsoft Spain.
Sofia, Bulgaria | 9-10 October.NET Windows Forms Tips and Tricks Cathi Gero Prenia Software & Consulting Services Cathi Gero Prenia Software.
DEV303 ASP.NET: Leveraging Visual Studio.NET For Web Projects Tony Goodhew Product Manager Microsoft Corp.
DAT 332 SQL Server 2000 Data Transformation Services (DTS) Best Practices Euan Garden Product Unit Manager SQL Server Development Microsoft Corporation.
DEV330 Visual Studio.NET IDE Tips and Tricks Billy Hollis Author / consultant.
Making the Most of WinForms 2.0 Data Binding Rajiv Sodhi Microsoft India.
DEV383 The ADO.NET DataSet and You Jackie Goldstein General Manager Renaissance Computer Systems
MSG331 Exchange Server 2000/2003 Software Development Kit Susan Hill Lead Programmer Writer Microsoft Corporation.
DAT300 SQL Server Notification Services: Application Development Ken Henderson Technical Lead, SQL Server Support Microsoft Corporation
MBL 305 ASP.NET Mobile Controls: Best Practices Gökşin Bakir CSA Yage Ltd. Microsoft Regional Director.
DEV395 No Touch Deployment for Windows Forms Jamie Cool Program Manager.NET Client Microsoft Corporation.
Windows Forms in Visual Studio 2005: An in-depth look at key features Name: Joe Stegman Title: Lead Program Manager Session code.
EBIZ302 Jupiter Business Process Automation and Web Services David Fong Program Manager.
DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation
DEV332 Programming for the Middle Tier in Visual Basic.NET Billy Hollis Author / Consultant.
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
EBIZ312 Connecting Host Systems to Microsoft Technologies Paul Larsen Aaron Grady Microsoft Corporation.
The 2007 Microsoft Office System Servers Enterprise Content Management, Workflow and Forms Martin Parry Developer and Platform Group, Microsoft Ltd
Workflow in Microsoft Office SharePoint Server Jessica Gruber Consultant Microsoft Corporation.
OFC320 Building EPM Solutions with Microsoft Project Server Ted Dinklocker Program Manager Microsoft Corp.
DAT 390 Advanced ADO.NET Programming Techniques Jackie Goldstein Renaissance Computer Systems
Office 365 Development July 2014.
Mike Harsh PRSL001 Program Manager Microsoft Corporation
Avalon – Using Data In Your Applications
Build data-driven collection and list apps using XAML
What's New in Visual Studio 2005
Chapter 10 Accessing Database Files
Windows Forms in Visual Studio 2005: An in-depth look at key features
Presentation transcript:

DEV393.NET Windows Forms Tips and Tricks Ken Getz Senior Consultant MCW Technologies, LLC

Me.About Senior Consultant with MCW Technologies, LLC Microsoft Regional Director, SoCal Technical editor for Access-VB-SQL Advisor ( Author of several developer’s books on ASP.NET, VB, Access, and VBA ASP.NET, VB.NET, ADO.NET, VB6 and Access video training for AppDev (

Special Thanks… Half of the topics in this session developed by Shawn Burke Development Manager,.NET Client Team

Eight Real-World Tips 1.Display Controls Your Way Owner-drawn ListBox and MenuItem 2.Use Data to Control the User Interface Working with the data bindings 3.Expose Protected Info with Inheritance Synchronized scrolling DataGrids 4.Improve the Look of Your Application Add XP Theming and non-rectangular windows

Eight Real-World Tips 5.Avoid Work When Drawing Controls ControlPaint class 6.Control DataGrid Formatting and Data Entry Use Column styles and DataView properties 7.Handle Single-Threaded Forms Use Invoke to handle thread switch 8.Allow Users to Easily Modify Settings Use the PropertyGrid control in your app!

Display Controls Your Way Use GDI+ to handle painting yourself Applies to (among others): ListBox/ComboBox MenuItem (set OwnerDraw property to True) For ListBox/ComboBox, set DrawMode property to one of: Normal OwnerDrawFixed OwnerDrawVariable

Drawing the Items Provide code for two events: MeasureItem Provide the width and height for each item Not used for List/ComboBox if DrawMode set to OwnerDrawFixed DrawItem Draw the item using GDI+ in the rectangle provided

It’s all in DrawEventArgs DrawEventArgs parameter provides: Bounds property: Rectangle containing the item Graphics property: Graphics context Index property: Index of current item State property: bit-flag property indicating current state of the item being drawn DrawBackground method DrawFocusRectangle method

Create Owner-Drawn ListBox and MenuItem demo demo

Using Data To Control UI Data binding can be used for more than just data Data binding infrastructure is very general and can bind almost any property to almost any value Notifications based on property change events Applications often want to show/hide/disable/enable controls based on the state of other controls

Controlling UI With Databinding demo demo

Expose Protected Info Much functionality of WinForms controls is protected Only available in control class, and in classes that inherit from the control What if you want to use protected functionality yourself? Must inherit from the control, and expose Can create real custom control Or can simply create a class in your project

Create Synchronized Scrolling DataGrids demo demo

Improving the Look of your Application Integrating Windows XP Visual Styles with your application Many controls can theme: system controls, ListView, TreeView, TabControl, Progress Bar Windows 2000, Windows XP Allow transparent top-level windows Control shapes can be modified with regions

Theming your Windows Forms Application demo demo

Avoid Work Drawing Three ways to create custom controls: Inherit from existing Create UserControl and its design surface Draw yourself, using GDI+ The last option made easier through the magic of the ControlPaint class Provides shared methods so you can easily create modified versions of standard controls

Create a Resizable Checkbox Control demo demo

Formatting a DataGrid Control By default, DataGrid shows all columns in all tables Using default settings for color, width, and formatting What if you want more control over the way the data looks? Use the GridTableStylesCollection Collection of DataGridTableStyle objects

Configuring with Properties Window Check out the TableStyles property Set MappingName property to match DataMember providing data Can also set general settings here Select GridColumnStyles to set up individual column styles Adds DataGridColumnStyle objects Set MappingName property (column name) Can set ReadOnly (see ProductID column) Show code generated by the designer

Writing Code You can also write code to manipulate styles: Dim dgCol As DataGridTextBoxColumn = _ CType(Me.styleOrderDetails. _ GridColumnStyles(2), DataGridTextBoxColumn) dgCol.Format = "c" dgCol.Alignment = HorizontalAlignment.Right

Limit Editing in DataGrid What if you want to allow edits, but not additions? Deletions, but not edits? Can set DataTable to be read-only, but that doesn't help DataView to the rescue Provides AllowEdit, AllowNew, AllowDelete properties All based on DataGrid binding to DataView

Formatting Columns and Handling Editing demo demo

Forms Aren’t Thread-Safe Call a Web Service asynchronously CLR retrieves a background thread from the thread pool Callback runs on the background thread Forms aren’t thread-safe You can’t reliably interact with the form from a background thread Can’t handle multiple threads updating properties concurrently

The Invoke Method Form (actually Control) provides Invoke method Runs a delegate on the thread that owns the form/control's window Calling Invoke performs a thread switch, and runs the called code on the host’s thread

Solving the Problem Examine the Original Code Create a Delegate Type Create the Delegate Instance and Call It Use Invoke method Pass array containing all parameters Sample displays thread information So you can verify the running thread

Handle Thread Switch using Invoke Method demo demo

Using the PropertyGrid in Your Application The PropertyGrid is the heart of the Property Browser in Visual Studio.NET The PropertyGrid provides a simple model for displaying property settings Easier and more space-efficient than laying out a dialog Can use a serializable object with properties to display, save, and load state

Using the PropertyGrid in Your Application demo demo

Ask The Experts Get Your Questions Answered Stop by Ask the Experts area 16:00 to 17:00, Wednesday

Community Resources Most Valuable Professional (MVP) Newsgroups Converse online with Microsoft Newsgroups, including Worldwide User Groups Meet and learn with your peers

evaluations evaluations

© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.