220 likes | 377 Views
Tips and Tricks: Answers to Common Questions when Building Windows Forms Applications. Mike Harsh PRSL001 Program Manager Microsoft Corporation. Agenda. 5 real world customer questions and solutions TabControl with tabs on bottom Docking confusion Read-only ComboBox
E N D
Tips and Tricks: Answers to Common Questions when Building Windows Forms Applications Mike Harsh PRSL001 Program Manager Microsoft Corporation
Agenda • 5 real world customer questions and solutions • TabControl with tabs on bottom • Docking confusion • Read-only ComboBox • Tracking the true visibility of a control in a container • DataBinding DateTimePicker to null • Questions
Non-Top Aligned TabsThe problem ComCtl v6 doesn’t implement other alignments Visual styles disabled Visual styles enabled
Non-Top Aligned TabsThe Solution • Draw the TabControl UI in code • Set ControlStyles.UserDraw to true
Docking ConfusionThe problem • Controls are docked based on their order in the Controls collection • This is known as Z-order • Docking issues due to Z-order can be tough to debug by looking at the designer
Docking ConfusionThe Solution • Use the new Document Outline window in Visual Studio • Ctrl+alt+t in the standard profile
ReadOnly ComboBoxThe problem ComboBox doesn’t support the concept of readonly Workaround of disabling the control doesn’t allow selection of text
ReadOnly ComboBoxThe Solution • Implement a ReadOnly property on a ComboBox subclass • Create a text field and a disabled button to place over the ComboBox
True Control Visibility The problem Visible property always returns the correct state. VisibleChanged is only raised when the Visible property of the control is modified It’s not raised when a control’s parent’s Visible property is set to false
True Control VisibilityThe Solution • Create a component that listens for all visibility changes and notifies a control when it is no longer on the screen • Uses a window hook on the thread and listen for the WM_SHOWWINDOW and WM_WINDOWPOSCHANGING messages • Users register a handler for a control visibility change
DataBinding DateTimePicker The problem • DateTimePicker has no UI for displayingNULL • DateTimePicker’s Value property is aDateTime • You cannot set NULL to a value type • Early bound compile error • Late bound exception • DataBinding infrastructure catches the exception, but doesn’t set the value
DataBinding DateTimePicker The Solution • Create a control that extends DateTimePicker and adds a Nullable<DateTime> property • Use the DateTimePicker’s check box as the null UI • Bind to the new property instead
Summary • 5 real world customer questions and solutions • TabControl with tabs on bottom • Docking confusion • Read-only ComboBox • Tracking the true visibility of a control in a container • DataBinding DateTimePicker to null
Community Resources • At PDC • Interesting in helping with Visual Studio and Developer Platform’s future planning? Sign up at the Tools and Language Track Lounge to attend a focus group. • For more information, go see • PRS321 Windows Forms: Integrating Windows Forms and Windows Presentation Foundation ("Avalon") (Thur 11:30am) • FUN222 Windows Vista: What’s New in Software Installation for Windows Vista: Exploring the Windows Installer (MSI) and ClickOnce Options (Fri 1pm) • Labs • FUNHOL15 ClickOnce Deployment • PRSHOL17 New UI Features in Windows Forms • PRSHOL18 New Data Features in Windows Forms • PRSHOL19 Windows Forms: Advanced Layout • The Windows Forms table in the Presentation track lounge • Ask The Experts • After PDC • MSDN dev center: http://msdn.microsoft.com/windowsforms/ • MSDN Forums: http://forums.microsoft.com/msdn/default.aspx?ForumGroupID=2
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.