Developing Windows and Web Applications using Visual Studio'NET Session 4: Better Windows Forms - PowerPoint PPT Presentation

1 / 89
About This Presentation
Title:

Developing Windows and Web Applications using Visual Studio'NET Session 4: Better Windows Forms

Description:

Hyperlinks. Buttons. Options: Infragistics. Janus Grid. Whidbey ... Hyperlink on a button. Bad Example #3. Normal button. Good Example. Image button ... – PowerPoint PPT presentation

Number of Views:238
Avg rating:3.0/5.0
Slides: 90
Provided by: Tatham
Category:

less

Transcript and Presenter's Notes

Title: Developing Windows and Web Applications using Visual Studio'NET Session 4: Better Windows Forms


1
Developing Windows and Web Applications using
Visual Studio.NETSession 4 Better Windows Forms
  • Jatin Valabjee
  • Eric Phan

2
Session Prerequisites
  • The browser over promises
  • Dont give the customer value
  • Too slow
  • The browser is a very weak and stupid program

3
.NET Pet Shop 2.0
4
.NET Pet Shop 2.0
5
  • so for the same reason I like Windows Forms as
    there is less code to write

6
Agenda
  • Goals
  • Why choose Windows Forms?
  • How to do efficient Windows Forms
  • Giving you a Toolkit

7
Rule 1 Do you know why you choose Windows Forms
8
Why Windows Forms
  • Bandwidth Presentation layer
  • Bandwidth - Compression
  • Cache
  • Vs. the browser button
  • Faster Server
  • Because of less requests and less work thanks to
    processing power being used on client
  • Richer interface
  • No buggy DHTML/JavaScript
  • More responsive
  • Faster to develop
  • No cross-browser issues
  • Build complex controls quickly
  • More people are happy!

9
Who Do I Please?
Browser Based Solution
Rich Client Solution
?
?
  • Network Admins
  • Developers
  • End Users
  • Accounts

?
?
?
?
?
?
Conclusion As .NET Framework becomes ubiquitous,
expect to see smart client applications
displacing browser-based apps, especially for
data-intensive purposes
10
Why NOT Windows Forms?
  • Not allowed in Standard Operating Environment
    (SOE)
  • Environment not known
  • Non-Windows OS

11
Rule 2Do you design a mockup UI first?
12
Designing a Mockup UI
  • Database schema should be designed before the
    mockup UI is started

13
Rule 3Do you use code generators?
14
Code Generation
  • Code Generation should be set up when the mockup
    is done
  • Have a _Regenerate.bat file to recreate data
    access layer stored procs

15
Rule 4Do you use red and yellow colors to
distinguish elements in the designer?
(1)
16
Red Yellow colours
  • Red for incomplete elements
  • Yellow for deliberately invisible elements

17
Rule 5Do your applications support XP themes?
  • In Visual Studio .NET 2003
  • Call Application.EnableVisualStyles() at the top
    of the Main method of the application
  • Set the FlatStyle property of each control to
    System
  • Bad Example Good Example

18
Rule 5Do your applications support XP themes?
  • In Visual Studio .NET 2005
  • Simply set it in the project property page

19
Rule 6Do you use inherited forms for consistent
behaviour?
(2)
20
Inherited Forms For Every Form
  • Common Behaviour
  • Company Icon
  • Remembering its size and location
  • Adding itself to a global forms collection if SDI
    (to find forms that are already open, or to close
    all open forms)
  • Logging usage frequency and performance of forms
    (load time)
  • No Controls!

21
StartPosition
  • CenterParent only for modal dialogs (to prevent
    multi-monitor confusion)
  • CenterScreen only for the main form (MainForm),
    or a splash screen
  • WindowsDefaultLocation for everything else (99
    of forms) - prevents windows from appearing on
    top of one another

22
FormBorderStyle
  • FixedDialog only for modal dialog boxes
  • FixedSingle only for the the main form (MainForm)
    - FixedSingle has an icon whereas FixedDialog
    doesn't
  • None for splash screen
  • Sizable for any form that has multi-line textbox,
    grid, listbox or such

23
Base Data Entry Form
3
4
1
2
24
Rule 7Do you encapsulate (aka lock) values of
forms?
(1)
25
Hiding Values
26
Hiding Values
  • Developers fiddle!

using System.ComponentModel Browsable(false),
EditorBrowsable(false) public new Font Font
get return base.Font set
base.Font value
Imports System.ComponentModelltBrowsable(False),
EditorBrowsable(false)gt _ Public Shadows
Property Font() As Font Get Return
MyBase.Font End Get Set(ByVal Value As
Font) 'MyBase.Font Value 'normal
property syntax MyBase.Font New
Font(Me.Font.FontFamily, 20) End SetEnd
Property
27
Rule 8Do you know when to use User Controls?
(2)
28
User Controls
  • Pros
  • You can use a user control more than once on the
    same form eg. Mailing Address, Billing Address
  • You can reuse logic in the code behind the
    controls e.g. Search control
  • User controls are less prone to visual
    inheritance errors
  • Cons
  • You lose the AcceptButton and CancelButton
    properties from the Designer eg. OK, Cancel,
    Apply. Therefore the OK, Cancel and Apply buttons
    cannot be on User Controls.

29
User Controls
  • Controls only used once
  • Bad!

30
User Controls
  • Only for reuse
  • Good!

31
User Controls TabPages
  • Exception!

32
User Controls TabPages
  • Possible Exception
  • When a form has multiple tabs, and each tab has
    numerous controls it can be easier to use User
    Control in this case
  • Smaller designer generated code
  • More than one person can be working on a
    different tab

33
Rule 9Do you know how to design a user friendly
search system?
(2)
34
Search System
  • Bad!

35
Search System
  • Good
  • Separate from entry fields
  • Advanced, field based, search criteria

36
Rule 10Do you use validator controls?
(1)
37
ErrorProvider
  • Code intensive
  • Must manually handle the Validating event of each
    control you want to validate
  • Must be manually running the validation methods
    when the OK or Apply button is clicked

38
Validator Controls
  • Good
  • No code, all in the designer (integrates with the
    ErrorProvider)

39
Validator Controls
  • One Final Thought
  • Unfriendly Msgboxs Upset People

40
Rule 11Do you use DataSets or create your own
business objects?
(2)
41
Passing data through layers
  • There are two kinds of people
  • Those that use DataSets
  • Those that want to use DataSets, but instead use
    Business objects

42
DataSets vs Business Objects
  • DataSets
  • Code Generation
  • CRUD functionality
  • Concurrency
  • Data binding
  • Business Objects
  • Better performance
  • Combine data storage with business logic

Developing Objects vs DataSets
43
Rule 12Do you use a status bar to show load
time?
  • Monitor Performance better
  • Good user feedback
  • Easy to do

44
Rule 13Do you not cache lookup data in your
Windows Forms application?
  • Leads to Synchronisation issues
  • Exception When application can be taken offline
    easily

45
Rule 14Do you use the designer for all visual
elements?
(2)
46
Exception
  • Bad Non-visual elements in designer

47
  • Good Only visual elements in designer

48
Rule 15Do you always use the Visual Studio
designer for data binding where possible?
(1)
49
Bad write your own boring code
Private Sub OnLoad() OrderDetailsService.
Instance.GetAll(Me.OrderDetailsDataSet1)
Dim row As OrderDetailsDataSet.OrderDetailsRow
Me.OrderDetailsDataSet1.OrderDetails(0)
Me.TextBox1.Text row.UnitPrice.ToString("c")
End Sub Private Sub Save() Dim row
As OrderDetailsDataSet.OrderDetailsRow
Me.OrderDetailsDataSet1.OrderDetails(0)
row.UnitPrice Decimal.Parse(Me.TextBox1.Text,
System.Globalization.NumberStyles.Currency)
End Sub
50
Using the Designer
  • SimpleBinding to a single property
  • ComplexBinding to a list

51
Rule 16Do you avoid using MDI forms?
(2)
52
MDI Forms
53
MDI Forms
  • Hangover from Access 2.0 and Windows 3.1
  • Clutter the application
  • Only one window on the taskbar
  • No multiple monitor support

54
Rule 17Do you have a correctly structured
common code assembly?
(2)
55
Note Also clean up directory BAD Which file do
you use?
56
Common Code Assembly
  • Good Use across multiple projects
  • Common (SSW.Framework.Common)
  • Code which is not UI specific
  • Example Code to convert a date into different
    formats
  • CommonWindows (SSW.Framework.WindowsUI)
  • Example Base forms which are the same for all
    products, wizard frameworks
  • CommonWeb (SSW.Framework.WebUI)
  • Example Generic XML-based navigation components

57
Rule 18Are your Data Access Layers compatible
with Web Services?
  • When running locally, use direct database
    connection.
  • When running remotely, use Web Services for
    better performance.

58
How?
  • Three ways to do it
  • Bad example
  • Lots of if statements (really messy - most people
    try this first)
  • Better example
  • Interfaces (Implements statement in VB)
  • Best Example
  • Factory pattern (best - most flexible and
    extensible approach)

59
Rule 19Do you include Exception Logging and
Handling?
(2)
60
Handling Exceptions
  • All unhandled exceptions should be logged
  • EMAB
  • Full source code provided by MS
  • Fully extensible with custom logging target
    extensions
  • Extended by SSW to log all exceptions
  • Log4Net
  • Open-source
  • Log writing methods of different severities
  • http//sourceforge.net/projects/log4net

61
SSW ExceptionReportingService
  • Web service which extends EMAB
  • http//webservice.ssw.com.au/exceptionreportingser
    vice/

62
Rule 20Do you make a strongly-typed wrapper for
App.config?
63
Not good
  • Bad

public static DatabaseAccessObjectFactory
CreateDataObjectFactory() return new
SqlDatabaseAccessObjectFactory(
ConfigurationSettings.AppSettings"ConnectionSt
ring")
  • Good

public static DatabaseAccessObjectFactory
CreateDataObjectFactory() return new
SqlDatabaseAccessObjectFactory(
AssemblyConfiguration.ConnectionString)
64
How to Do it
using System using System.Configuration namespa
ce SSW.Northwind.WindowsUI public sealed
class AssemblyConfiguration // Prevent
the class from being constructed private
AssemblyConfiguration() public static
string ConnectionString get
return ConfigurationSettings.AppSettings"Conne
ctionString".ToString()

65
Rule 21Do you replace the standard .NET
DataGrid?
66
Reasons
  • Need sorting on column headings (when you bind to
    data objects)
  • Combo box
  • Hyperlinks
  • Buttons
  • Options
  • Infragistics
  • Janus Grid

67
Whidbey DataGridView
68
Rule 22Do you replace the standard .NET date
time picker?
  • Doesnt take Null

69
Rule 23Do you avoid 3rd party menus toolbars?
  • We have tried several third party menu and
    toolbar controls and all of them had serious bugs

70
Menus Toolbars in Whidbey
  • Office 2003 style menus and toolbars with the new
    ToolStrip control
  • Easy to upgrade to
  • Upgrading from 3rd party controls will be
    difficult

71
Rule 24Do your List Views support multiple
selection and copying?
  • Bad Example

72
  • Good Example Multiple select Copy

73
Rule 25Do you use an image button for opening a
web page taking action?
  • Note Simple Links are for navigation only (no
    action taken)

74
Bad Example 1
  • Simple Hyperlink

75
Bad Example 2
  • Hyperlink on a button

76
Bad Example 3
  • Normal button

77
Good Example
  • Image button
  • In this example, the action is generating
    reports, passing and processing values

78
Rule 26Do your forms have Accept and Cancel
buttons?
79
Rule 27Do you name your Accept button OK or
Next?
80
  • If wizard, it should be Next, otherwise OK.

81
Rule 28Do you make common control with certain
width?
82
Bad/Good Example 1
83
Bad/Good Example 2
84
Rule 29Do your Windows Forms applications
support URLs?
85
URLs in Outlook
86
URLs
  • Q What does a browser have that a Windows
    Application doesnt have?
  • A A URL

87
Rule 27Do you include Back and Undo?
  • Store the previous actions in a dataset in
    memory.
  • Example Outlook Advanced toolbar

88
Rule 28Do you use NUnit to write Unit Tests?
  • Assumed
  • But what about the GUI

89
  • http//www.windowforms.net
  • http//www.ssw.com.au/SSW/Standards/
  • Please plan for Whidbey

90
SSW .NET Toolkit
  • http//www.ssw.com.au/SSW/NetToolkit

91
2 things
JatinValabjee_at_ssw.com.au EricPhan_at_ssw.com.au
92
Thank You!
93
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com