|
|
mcts 70-526 notes
Chapter 1, Windows Forms and the User Interface
- Form: WindowState sets startup state, Text sets caption, FormBorderStyle sets border and resizing.
- For non-rectangular forms use no border and assign the Form’s Region property in Form_Load event.
- Container controls: Panel, FlowLayoutPanel, TableLayoutPanel, TabControl, SplitContainer, GroupBox.
- Add control to Form: Form.Controls.Add().
- Anchor: Constant distance to edge.
- Dock: Zero distance to edge and fills out the edge.
- Form events: HandleCreated, BindingContextChanged, Load, VisibleChanged, Activated, Shown.
Chapter 2, Configuring Controls and Creating the User Interface
- Layout toolbar to position controls at design time.
- Document Outline Window to see and edit the control hierachy.
- MaskedTextBox: Display format to enter and validate user input.
Chapter 3, Advanced Windows Forms Controls
- ListBox, ComboBox, CheckedListBox, ListView, TreeView, NumericUpDown, DomainUpDown.
- CheckBox, RadioButton, TrackBar, DateTimePicker, MonthCalender, ImageList, PictureBox.
- CheckBox has ThreeState property. Gives the Indetermine option. Can be used as preset value also when ThreeState is disabled.
- WebBrowser, NotifyIcon.
- Access keys: a. Direct: Text property with & and UseMnenomic = true, b. In label: Text property with &, UseMnenomic = true and TabIndex-1 of control to access.
- ProgressBar has default values: Min – 0, Max – 100.
Chapter 4, Tool Strips, Menus and Events
- ToolStrip/StatusStrip control has ToolStripItem controls.
- ToolStripItem: Label, Button, TextBox, ComboBox, ProgressBar, SplitButton, DropDownButton, Separator.
- MenuStrip hosts ToolStrip and ToolStripMenu items.
- Set Checked property or use CheckOnClick = true to view a check mark in menu item.
- ContextMenuStrip control to display context menus.
- Mouse and keyboard events.
- Differnece btw. MouseDoubleClick and DoubleClick event: DoubleClick is with left key only.
- Use ShortcutKey property and Enable = true for short-cut keys.
- Enter button triggers Click event on Control in focus.
Chapter 8, Implementing Data-Bound Controls
- Create DataSet using the Data Source Configuration Wizard.
- Create front end controls using Show Data Sources from Data menu.
- Simple databinding: Use Control.DataBindings.Add() with a BindingSource object.
- Complex databinding: Use DataSet/BindingSource/other source and attach it to Control.DataSource using Control.DataMember.
- Use BindingNavigator or BindingSource.MoveXXXX methods to navigate through a BindingSource.
- DataGridView control and it’s columns.
- Use CellPainting event handler to style the DataGridView.
Chapter 10, Printing in Windows Forms
- PrintDocument has PrinterSettings and PageSettings.
- Use PrintDialog and PageSetupDialog with the PrintDocument associated to let user change the settings.
- Use PrintPreviewDialog with associated PrintDocument to preview.
- For printing a PrintDocument the PrintPage event is raised for each page to print (3 pages – 3 event executions).
- Use the Graphics object in PrintPageEventArgs and remember to implement multi-page logic.
- EndPrint event.
- PrintingPermission: AllPrinting, DefaultPrinting, SafePrinting, NoPrinting.
- Use the PrintPreviewControl for better customization.
- Determine total lines of page: e.MarginBounds.Height / myFont.GetHeight(e.Graphics).
- Internet applications receive SafePrinting permission level.
Chapter 11, Advanced Topics in Windows Forms
- Drag and Drop
- Call the DoDragDrop method in MouseDown event handler on source control and make sure that AllowDrop is set to true on target control.
- Use QueryContinueDrag to cancel a drag and drop operation.
- Handle the DragEnter event on target control. Set e.Effect to a matching effect for source control.
- Handle the DragDrop event on target control. Retrieve Data from DragEventArgs.GetData, pressed keys from DragEventArgs.KeyState and allowed effects from DragEventArgs.AllowedEffect. Typically the KeyState is used to determine the action (effect) to execute when the item is dropped on the target. AllowedEffect property is used to make source and target control agree on the effect. Source and target effect have to match.
- Neutral culture: language but no region.
- Specific culture: language and region.
- Set CurrentThread.CurrentCulture to change globalization for the application. Set CurrentThread.CurrentUICulture to change localization.
- Set Localizable to true and Language to "…" for creating a localized form in anohter language.
- Set RightToLeft property to change orientation of control (default is inhert) and RightToLeftLayout property on form.
- MDI forms: Multi document interface.
- Set IsMdiContainer to true for MDI parent form.
- Set MdiParent to parent form instance to create child form and call the child’s Show().
- Form.ActiveMdiChild returns the active/selected child form.
- Use Form.LayoutMdi() to change the layout: ArrangeIcons, Cascade, TileHorizontal, TileVertical.
- Use MdiWindowListItem property on a MenuStrip to create a child form window list.
- Use Clipboard class to access it.
Chapter 12, Enhancing Usability
- You can use the system’s settings for fonts, colors, brushes, icons and pens by using the respecitve SystemXXXX class.
- All windows controls have AccessibleXXXX properties.
- Display info to user with: StatusStrip, ProgressBar.
- For user assistance use: HelpProvider, ErrorProvider and ToolTip.
- ToolStripStatusLabel and ToolStripProgressBar are typically used in StatusStrip.
- Use ToolTip.SetToolTip(Control, string) to assign a tooltip and tooltip text to a control. Set Active = true.
- ErrorProvider.SetError(Control, string) shows error message as tooltip and highlights the control. Is typically used from a Contol’s validation event handler. Has aslo complex databinding. Set ContainerControl to form and use DataRow.SetColumnError().
- HelpProvider shows Help 1.x when F1 is pressed.
- SoundPlayer plays wav files. System sounds can be accesses via System.Media.SystemSounds.
- Timer control.
Chapter 13, Asynchronous Programming Techniques
- BackgroundWorker.RunWorkerAsync() to execute code in background thread. Code in DoWork() is run.
- RunWorkerCompleted handler when finished. e.Cancelled and e.Result event args properties.
- Cancel: Set WorkerSupportsCancellation to true, call Cancel and implement cancellation in DoWork() setting e.Cancelled to true and return.
- Progress: Call ReportProgress() and handle in ProgressChanged event and set WorkerReportsProgress to true.
- Delegate invokation: Declare delegate for method to invoke, instantieate the delegate and run it’s BeginInvoke(). Calling the EndInvoke() will block the thread until the invoked method returns.
- Call EndInvoke()
- Poll IAsyncResult
- Use call back method
- For in-depth threading info: http://msdn2.microsoft.com/en-us/library/3e8s7xdd.aspx.
- Thread.Start(), Thread.Abort(): deadlocks, race condidtions.
- Locking an object: lock(anObject).
- Locking a collection: lock(ArrayList.SyncRoot). Create locking objects to boost performance on generic classes. Requires simply an object instance.
- To access form controls from different threads use Control.InvokeRequired() and Control.Invoke() when required.
Chapter 14, Creating Windows Forms Controls
-
Extend form controls in the following ways:
-
Composite controls: mixing of existing controls.
-
Custom controls: control from scratch with it’s own Draw method.
-
Extending existing controls.
-
Add new UserControl and add some constitutent controls.
-
ToolBoxBitmap to specifiy toobox icon.
-
Custom controls inherit from Control and implement the OnPaint method.
-
Call Dispose() on Pen, Brush and Graphics objects for better performance.
-
Obtain Graphics object from Control.CreateGraphics on PaintEventArgs in OnPaint method.
-
Modal Dialog – blocks execution. ShowDialog().
-
Modeless Dialog – continues execution. Show().
Chapter 15, Deployment
-
Click-once: Solution/Properties/Publish. Can be published to file path, network share, ftp or http. Run setup.exe or publish.htm to run.
-
Setup and Deployment project to create MSI installers.
-
Editors: File System, Registry, File Types (associations), User interface (Wizard), Custom Actions, Launch Conditions.
-
Add project output by right-click on Application Folder in File System Editor.
-
VersionNT = major x 100 + minor. E.g. Win2k >= 500.
-
Windows9X version: Windows 98 >= 410, Windows ME >= 490.
-
Custom Action Editor assigns Installer classes to the MSI or runs any specified method. Use Exception handling in install code and throw InstallException which rolls back.
-
ProjectInstaller class does not require to specify EntryPoint in Custom Action.
-
Application icon (Menu) is set in File System Editor.
-
Click-Once applications are not installed in Program Files folder.
-
Click-Once deploys these files: MyApp.exe.manifest, MyApp.exe.deploy, MyApp.application, Setup.exe.
-
ProductName and Manufacturer determine the install path.
|
|