Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Forms A new plattform for Windows-based application development.

Similar presentations


Presentation on theme: "Windows Forms A new plattform for Windows-based application development."— Presentation transcript:

1 Windows Forms A new plattform for Windows-based application development

2 Overview Section 1: Introduction Section 2: Forms Section 3: Using Controls Section 4: Data bound Controls Section 5: User Controls Section 6: Miscellaneous Summary

3 Introduction Basic concepts From Window to Control to Form Delegates and Events The Control class Forms Inheritance Creating and using instances The System.Drawing namespace

4 Basic concepts A window is the core component of Windows Configured via attributes SendMessage is the most important function Not really object oriented MFC as C++ oriented improvement New library for the.NET framework Windows Forms

5 From Window to Control to Form One common base class: Control Represents a window Offers properties and methods The Form class is derived from Control New Controls and Forms through Inheritance

6 Delegates and Events The control‘s way to send a message: an event Delegates Object oriented function pointers The base of modern callback functions Delegates are type safe Events are based on delegates Act as connection points More than one handler possible Windows Forms: Overridable methods

7 The Control Class Implements basic functionality Base class for predefined classes Indirect base class for user controls A lot of properties and methods Color, position, size, child controls Enhanced functionality Docking, special message handling No painting implemented

8 Forms Application windows Different forms: standard, tool, dialog Own forms through inheritance Special attributes DesktopLocation, AcceptButton, ShowDialog

9 Inheritance New window types through inheritance Old methods: API: WNDCLASS VB: Form class or User Control (ActiveX).NET method Inherited from (User)Control or Form Really object oriented

10 Creating and using Instances Very familiar to Visual Basic programmers Form Create instance Call the Show or ShowDialog method Use properties and methods Control Create instance Add to the containers Controls collection Use properties and methods

11 The System.Drawing namespace Special data structures for position and so on Defined in the System.Drawing namespace Point for position Rectangle and Size for dimensions Color für Color values Graphics encapsulate a Device Context Drawing functions and elements

12 Forms GUI based applications Forms Forms and contained Controls Dialogs MDI applications

13 GUI based applications Use SYSTEM.WINDOWS.FORMS.DLL Main function as entry point Application class for message loop The Run method opens the main form User defined Form class for the main window Override OnPaint for output Override other event method for input handling

14 Forms New concepts ClientSize instead of ScaleWidth, ScaleHeight New names for known elements Unload goes to Closing New properties and functions DesktopLocation, DesktopBounds

15 Forms and contained Controls Adding a control to a form create the control instance set the attributes of the control (Text, BackColor,…) set the location and dimensions of the control add event handlers for the control add the control to the controls collection of the form

16 Dialogs Use ShowDialog to open a dialog Returns a DialogResult value How is the dialog closed OK, Cancel, Yes,... AcceptButton, CancelButton properties Extra OK and Cancel button handling Return input values via Public Controls Public properties Special dialog type: MessageBox

17 MDI applications Combination of Container and Child Form IsMdiContainer property indicates the container MdiParent property refers to the Container Used by the Child Form Other elements ActiveMdiChild: active child form MdiChildren: child forms array

18 Using Controls Layout Buttons Text Controls List Controls Menus Common Dialogs More controls

19 Layout Dynamic position of controls Old: Calculate and move New: Anchoring and Docking Anchor Fixed distance to borders Dock Connecting to an edge Splitter

20 Buttons Abstract base class: ButtonBase Button class for push buttons DialogResult property CheckBox ThreeState, AutoCheck property RadioButton AutoCheck property

21 Text Controls Base class TextBoxBase New functions Lines property gets, sets a string array Select method selects a range of text in the text box AppendText method appends text TextBox and RichTextBox are inherited classes TextBox Character casing, Password handling RichTextBox Supports RTF DetectUrls, AutoWordSelection properties

22 Simple List Controls ListBox Items are stored in an ObjectCollection Additional collections for selected items SelectedIndexCollection, SelectedObjectCollection Enhanced and new functions ComboBox Combination of ListBox and TextBox CheckedListBox Owner Draw Mode

23 Complex List Controls ListView (Multi column) list of items Collections for Columns, Items and so on More values as columns possible TreeView Hierarchical list of items ImageList Stores images for other controls

24 Menus Realized by a class hierarchy Abstract base class Menu MenuItem class for single items MainMenu class for the forms main menu ContextMenu class for shortcut menus Useful events Popup, MenuStart: context dependant states Select: User feedback

25 Toolbars 2 classes: ToolBar + ToolBarButton Buttons with different styles Dropdown menus supported Toggle buttons supported ButtonClick + ButtonDropDown events No events for status handling Use the Application.Idle event instead

26 Common Dialogs OpenFileDialog, SaveFileDialog Derived from FileDialog Offers the OpenFile method FontDialog Raises an Apply event for preview functionality ColorDialog PageSetupDialog PrintDialog

27 More Controls Tabbed views TabControl and TabPage StatusBar Bar and Panels Miscellaneous PictureBox, LinkLabel, Timer, UpDown TrackBar, Scrollbars, ProgressBar MonthCalendar, DateTimePicker

28 Data bound Controls ADO.NET Managed Providers Using the OLE DB.NET Provider Data Binding Simple data binding Complex data binding

29 ADO.NET New data access technology Two core components DataSet.NET Managed Providers DataSet contains other components DataTable DataRelation Tight integration with XML

30 Managed Providers Data Source/Database access Connection: Access to a data source Command: SQL statements DataAdapter Bridge between DataSet and Database OLE DB.NET Provider Native OLE DB through COM Interop SQL Client.NET Provider SQL Server specific protocol

31 Using the OLE DB.NET Provider OleDbConnection ADO like connection string OleDbCommand SQL statements: Select, Insert, Update OleDbDataReader Read only, forward only, fast OleDbDataSet Fill a DataSet

32 Data Binding Two types Simple data binding Label, TextBox, PictureBox Complex data binding DataGrid, ComboBox Possible data sources DataSet, DataTable, DataView, DataSetView 1-dimensional Array, Collection

33 Simple data binding Binding a control to a data source Binds one data field Binds a property of the control The Binding classes Binding BindingContext BindingManagerBase CurrencyManager

34 Complex data binding Bind more than one data field Properties DataSource DataMember Method SetDataBinding Updates by DataSet operations

35 User Controls Reusing existing controls Extending standard controls Composite controls Custom Controls Implemented from scratch Design time support Attributes Type converter and editor, designer

36 Reusing Existing Controls Extending existing controls Using standard controls as base class Rich base functionality Focus on new functions Composite controls Derived from UserControl Combines standard controls LabelTextbox: Label + TextBox

37 Custom Controls „Normal“.NET Controls Implementation is straightforward Derived from System.Control Sometimes from UserControl Implemented from scratch Overrides OnPaint for display Special property support ShouldSerialize, Reset

38 Design time support (1) Better cooperation with designers Support for UDTs Converter + editor For properties and events Based on attributes Browsable: displayed in the property browser Description: describes the property DefaultValue: a simple default value TypeConverter: a special converter

39 Design time support (2) Type converter Converts from and to UDTs UI Type Editor Visual editing of UDTs Type specific Dialogs Custom Designer Supports special design time demands

40 Miscellaneous ActiveX Controls Special message handling IMessageFilter interface PreProcessMessage Related classes Keys Cursors System Information

41 ActiveX Controls Usable through wrappers Aximp.exe generates control class Creation via New statement Usage like other controls Special initialisation BeginInit, EndInit Main function requirers STAThread attribute

42 Special Message Handling IMessageFilter interface Early message handling 1 method: PreFilterMessage Used by the Splitter control PreProcessMessage After PreFilterMessage, before any event Some related functions ProcessCmdKey, ProcessDialogKey IsInputKey, IsInputChar

43 Related classes Keys Cursors SystemInformation

44 Summary Windows Form is Straightforward Really object oriented Feature rich Easy to use


Download ppt "Windows Forms A new plattform for Windows-based application development."

Similar presentations


Ads by Google