MCAD 70-306

Creating User Services

Create a Windows Form by using the Windows Forms Designer

  1. Create a Windows Application
  2. Click the form to select it
  3. Using the Properties window, click Text and type MCAD Preparation...
  4. Click StartPosition to reveal its combo box. Then click its combo box and select CenterScreen
  5. Change the Minimize Box property to False
  6. Test the application
  1. Create a Windows Application
  2. To add another form, on the main menu, click Project -> Add Windows Form...
  3. Set the Name of the form to About and press Enter
  4. Click the middle of the form to select it
  5. In the Properties window, click Text and type About this Application...
  6. Click FormBorderStyle, then click its combo box and select FixedDialog
  7. Set both MaximumBox and MinimizeBox to False
  8. On the Toolbox, click Button and click the form
  9. While the new button is still selected, in the Properties, change its Text to Close and its Name to btnClose
  10. Double-click the Close button and implement its Click event as follows:
     
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Close()
        End Sub
  11. Display the first form and add a button to it
  12. Change its Text to About and its Name to btnAbout
  13. Double-click the Second button and implement its Click event as follows:
     
    Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
            Dim frmAbout As Form
            frmAbout = New About
    
            frmAbout.Show()
        End Sub
  14. Test the application and then close it
  15. To add an inherited form, on the main menu, click Project -> Add Inherited Form...
  16. Set the Name of the new form to Helper and click Open
  17. In the Inheritance Picker, click About and click OK
  18. Add a new Button to the new form
  19. Set its Text to Validate and its Button to btnValidate
  20. Double-click the new Validate button and implement its Click event as follows:
     
    Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click
            MsgBox("This is an acknowledgement from the inheritance")
        End Sub
  21. Display the About form and add a CheckBox to it
  22. Double-click the CheckBox control and implement its event as follows:
     
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            If Me.CheckBox1.Checked Then Text = "Checked"
            If Me.CheckBox1.Checked = False Then Text = "Non Checked"
        End Sub
  23. Display the first form and add a new button to it
  24. Set its Text to Helper and its Name to btnHelper
  25. Double-click the Helper button and implement its Click event as follows:
     
    Private Sub btnHelper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelper.Click
            Dim frmHelp As New Helper
    
            frmHelp.ShowDialog()
    End Sub
  26. Test the application
  1. Start a Windows Application
  2. Right-click the middle of the form and click View Code
  3. In the class Name combo box, select (Form1 Events)
  4. In the Method Name combo box, select Paint and implement it as follows:
     
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Dim PenRed As New Pen(Color.Red, 2)
    
            e.Graphics.DrawRectangle(PenRed, 20, 20, 350, 270)
    End Sub
  5. Test the application

Add controls to a Windows Form

  1. Create a Windows Application named MCAD4
  2. Click the middle of the form to select it
  3. In the Properties window, click Text and type Microsoft Certified Application Developer
  4. On the Toolbox, click GroupBox and click the form
  5. While the new control is still selected, in the Properties, change its Text to Pizza Size
  6. Click the + of Location to expand it
  7. Under Location, click X and type 12
  8. Click Y and type 18
  9. Click the + of Size
  10. Under Size, click Width and type 150
  11. Click Height and type 120
  12. From the Toolbox, click RadioButton and click inside the GroupBox
  13. Add two more RadioButton controls and arrange them to be distinct
     

     
  14. Click the top radio button. In the Properties window, change the following:
     
    Text: Small
    Name: rdoSmall
    Checked: True
     
  15. Click the middle radio button. In the Properties window, change the following:
     
    Text: Medium
    Name: rdoMedium
     
  16. Click the lower radio button. In the Properties window, change the following:
     
    Text: Large
    Name: rdoLarge
     
  17. Add a Label to the right of the GroupBox
  18. Set its Text to Pizza Price:
  19. Add a TextBox to the right side of the label
  20. Set its properties as follows:
     
    Text: 7.55
    TextAlign: Right
    Name: txtPizzaPrice
  21. Add a button to the form. Set its Text to Close and its Name to btnClose
     
  22. Save the application
  1. Start a Windows Application named MCAD5
  2. Right-click the middle of the form and click View Code
  3. In the top section of the form, declare a Button variable named btnSubmit
     
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim btnSubmit As Button
    
  4. In the New() constructor of the form, type code to dynamically create the button
     
    Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
            btnSubmit = New Button
            btnSubmit.Text = "Submit"
            btnSubmit.Left = (Me.Width \ 2) - 40
            btnSubmit.Top = 40
    
            Me.Controls.Add(btnSubmit)
    End Sub
  5. Save and test the application
  1. Create a Sub procedure as follows:
     
    Private Sub Submitter(ByVal sender As Object, ByVal e As EventArgs)
            MsgBox("Your employment application has been submitted. We will get back to you")
        End Sub
  2. In the New() constructor of the form, specify the code to handle the event of the dynamically created control:
     
    Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
            btnSubmit = New Button
            btnSubmit.Text = "Submit"
            btnSubmit.Left = (Me.Width \ 2) - 40
            btnSubmit.Top = 40
            AddHandler btnSubmit.Click, AddressOf Submitter
    
            Me.Controls.Add(btnSubmit)
    End Sub
  3. Test the application
  1. Open the MCAD4 application
  2. Double-click each radio button and implement their events as follows:
     
    Private Sub rdoSmall_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoSmall.CheckedChanged
            Me.txtPizzaPrice.Text = "$7.55"
    End Sub
    
    Private Sub rdoMedium_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoMedium.CheckedChanged
            Me.txtPizzaPrice.Text = "$9.35"
    End Sub
    
    Private Sub rdoLarge_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoLarge.CheckedChanged
            Me.txtPizzaPrice.Text = "$11.25"
    End Sub
  3. Double-click the Close button and implement its Click event as follows:
     
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
            End
    End Sub
  4. Save and test the application

Implement navigation for the user interface (UI)

Validate user input

Implement error handling in the UI

Implement online user assistance

Incorporate existing code into a Microsoft Windows-based application

Display and update data

Instantiate and invoke a Web service or component

Implement globalization

Create, implement, and handle events

Implement print capability

Implement accessibility features

Creating and Managing Components and .NET Assemblies

Create and modify a .NET assembly

Create a Windows control

Consuming and Manipulating Data

Access and manipulate data from a Microsoft SQL Server™ database by creating and using ad hoc queries and stored procedures

Access and manipulate data from a data store. Data stores include relational databases, XML documents, and flat files. Methods include XML techniques and ADO .NET

Handle data errors

Testing and Debugging