15. building applications with windows forms
DESCRIPTION
15. Building Applications with Windows Forms. Why Use Windows Forms? Structure of Windows Forms Using Windows Forms Using Controls. Code Samples. Why Use Windows Forms?. Accessibility support Visual inheritance Extensible object model Advanced forms design. Rich set of controls - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/1.jpg)
1
15. Building Applications with Windows Forms Why Use Windows Forms?Structure of Windows FormsUsing Windows FormsUsing Controls
Code Samples
![Page 2: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/2.jpg)
2
Why Use Windows Forms?Rich set of controlsFlat look styleAdvanced printing
supportAdvanced graphics
support – GDI+
Accessibility support
Visual inheritance
Extensible object model
Advanced forms design
![Page 3: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/3.jpg)
3
• Structure of Windows Forms
Windows Forms Class HierarchyUsing the Windows.Forms.Application ClassExamining the Code Behind Windows Forms
![Page 4: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/4.jpg)
4
Windows Forms Class Hierarchy
Control
ContainerControl
Form
UserControl
ScrollableControl
![Page 5: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/5.jpg)
5
Using the Windows.Forms.Application Class
static void Main() { frmCustomers f = new frmCustomers(); f.Show(); Application.Run(); }
Allows the application to continue after the form is closed
![Page 6: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/6.jpg)
6
Examining the Code Behind Windows Forms Imports
To alias namespaces in external assemblies
Class Inherits from System.Windows.Forms.FormConstructor – public frmCustomers() Initializer – private void InitializeComponent()Destructor – protected override void Dispose( … )
using Winforms = System.Windows.Forms;using Winforms = System.Windows.Forms;
![Page 7: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/7.jpg)
7
Using Windows Forms
Using Form PropertiesUsing Form MethodsUsing Form EventsHandling EventsCreating MDI FormsUsing Standard Dialog Boxes
![Page 8: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/8.jpg)
8
Using Form Properties
DialogResultFontOpacityMaximumSize and MinimumSizeTopMostAcceptButton and CancelButton
![Page 9: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/9.jpg)
9
Using Form MethodsClose
ShowDialog and Show
if blnEndApp = true {
this.Close( );}
if blnEndApp = true {
this.Close( );}
//Create a second form frmCustomerDetails f = new frmCustomerDetails(); //Show as a dialog box (modal) //f.ShowDialog(); //Show as a owned form (non-modal) this.AddOwnedForm(f); f.Show();
//Create a second form frmCustomerDetails f = new frmCustomerDetails(); //Show as a dialog box (modal) //f.ShowDialog(); //Show as a owned form (non-modal) this.AddOwnedForm(f); f.Show();
![Page 10: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/10.jpg)
10
Using Form Events
Activated and DeactivateClosingClosed
![Page 11: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/11.jpg)
11
Handling Events
Handling multiple events with one procedure
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);this.btnEdit.Click += new System.EventHandler(this.btnAdd_Click);
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);this.btnEdit.Click += new System.EventHandler(this.btnAdd_Click);
![Page 12: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/12.jpg)
12
Creating MDI Forms
Creating the parent form
Creating child forms
Accessing child forms Arranging child forms
this.IsMdiContainer = true;this.WindowState = FormWindowState.Maximized;
this.IsMdiContainer = true;this.WindowState = FormWindowState.Maximized;
Form2 doc = new Form2( );doc.MdiParent = this;doc.Show( );
Form2 doc = new Form2( );doc.MdiParent = this;doc.Show( );
![Page 13: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/13.jpg)
13
Using Standard Dialog Boxes
MsgBox
MessageBox Class
InputBox
if (MsgBox("Continue?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Question") == MsgBoxResult.Yes){ ...}
if (MsgBox("Continue?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Question") == MsgBoxResult.Yes){ ...}
if (MessageBox.Show("Continue?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)= DialogResult.Yes){ ...}
if (MessageBox.Show("Continue?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)= DialogResult.Yes){ ...}
![Page 14: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/14.jpg)
14
Demonstration: Manipulating Windows Forms
![Page 15: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/15.jpg)
15
Using Controls
New ControlsUsing Control PropertiesUsing Control MethodsCreating MenusProviding User Help Implementing Drag-and-Drop Functionality
![Page 16: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/16.jpg)
16
Using Control Properties
PositioningAnchorDockingLocation
Text property
![Page 17: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/17.jpg)
17
Using Control Methods
BringToFront and SendToBack
FocusTextBox1.Focus( );TextBox1.SelectAll( );
TextBox1.Focus( );TextBox1.SelectAll( );
Button1.BringToFront( );Button2.SendToBack( );
Button1.BringToFront( );Button2.SendToBack( );
![Page 18: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/18.jpg)
18
Providing User Help
ErrorProvider controlError icon appears next to control, and message
appears like a ToolTip when mouse pauses over iconUsed mainly for data binding
HelpProvider controlPoints to .chm, .hlp, or .html Help fileControls provide Help information by means of
HelpString or HelpTopic properties
![Page 19: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/19.jpg)
19
Demonstration: Using Controls
![Page 20: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/20.jpg)
20
Implementing Drag-and-Drop Functionality
Starting the process Use the DoDragDrop method in the MouseDown
event of the originating control
Changing the drag icon Set the AllowDrop property of the receiving
control to True Set the Effect property of the DragEventsArg in
the DragOver event of the receiving control
Dropping the data Use the Data.GetData method to access the data
![Page 21: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/21.jpg)
21
Demonstration: Implementing Drag-and-Drop Functionality
![Page 22: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/22.jpg)
22
Advanced Features OverviewEnhanced Design-Time SupportNew Controls and ComponentsNew Data-Binding Model and FeaturesAsynchronous ProgrammingOther Significant New FeaturesDemonstration: RAD Data BindingWhat Is ClickOnce?Features and Benefits
![Page 23: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/23.jpg)
23
New Controls and ComponentsFlowLayoutPanel and TableLayoutPanel controlsSplitContainer controlToolStrip, MenuStrip, StatusStrip, and
ContextMenuStrip controlsDataGridView controlBindingNavigator controlMaskedTextBox controlWebBrowser control
![Page 24: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/24.jpg)
24
New Data-Binding Model and Features BindingSource component
Layer of indirection/abstraction between controls and data sourceCan act as strongly typed data sourceInteroperates closely with BindingNavigator and DataGridView
controls Data components (concept-not class/component)
Building blocks of typed DataSetConsist of DataTables, TableAdapters, TableAdapter queriesCreate/edit using DataSet Designer
Data sources (concept-not class/component)Simplified management of data sourcesEnable drag-and-drop creation of data-bound forms
Smart tags
![Page 25: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/25.jpg)
25
Asynchronous ProgrammingBackgroundWorker component
DoWork, RunWorkerCompleted, ProgressChanged eventsRunWorkerAsync, CancelAsync, ReportProgress methods
Asynchronous Pattern for ComponentsUsed by .NET Framework components with long-running
methodsPictureBox has Load and LoadAsync methods, and a
LoadCompleted event
![Page 26: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/26.jpg)
26
What is ClickOnce?
ClickOnce is a new application deployment technology
It makes deploying Windows applications as easy as deploying Web applications
Application updates are easy to administer
![Page 27: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/27.jpg)
27
Features and BenefitsClickOnce applications are low impact
No administrative rights are required on the client machineDeployment is through Web servers, CDs, or file systemsApplications can be installed on the client machine or can
run remotelyClickOnce applications execute in a secure environmentVisual Studio provides a rich set of support features for
publishing ClickOnce applicationsPrerequisite software can be installed alongside the
application installation
![Page 28: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/28.jpg)
28
Review Why Use Windows Forms? Structure of Windows Forms Using Windows Forms Windows Forms Inheritance Enhanced Design-Time Support New Controls and Components New Data-Binding Model and Features Asynchronous Programming What Is ClickOnce?
![Page 29: 15. Building Applications with Windows Forms](https://reader035.vdocuments.us/reader035/viewer/2022062517/56812e07550346895d936e65/html5/thumbnails/29.jpg)
29
Lab 15: Building Applications with Windows Forms
Exercise 1: Using the layout properties of the controls and form
Exercise 2: adding a ToolStrip and a ToolTip control
Exercise 3: Opening forms and using the new container controls & provider controls