Hot-Link Menu in Right-Side Column

Last Updated 6-30-2010


 
MoreNotebooks.php
  • More Computers
  •  
    MoreSonyPSP.php
  • More Games
  •  
    Morecellular.php
  • More Electronics
  •  
    MoreComputerScienceBooks.php
  • More Books
  •  
    MoreProgramming.php
  • More Software
  • Multiform Project Example - Part III

    Select the Form1.vb Screen tab located at the top of the design window, or double-click in a blank area of Form 1 to bring up the Form1 Code View Window. Enter the following code:

    Public Class MainForm
    
        Private Sub Form1_Load(ByVal sender As System.Object, _
    		ByVal e As System.EventArgs) Handles MyBase.Load
    
            MyDogPicture.Height = 150
            MyDogPicture.Width = 138
            MyDogPicture.ImageLocation = "http://centurion2.com/HTML/Tutorial/Dog3.JPG"
    
        End Sub
    
       Private Sub btnChangeName_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnChangeName.Click
    
            frmChangeName.Show()
    
        End Sub
    End Class
    						

    Figure MFP-11: Visual Basic Source Code for frmMainForm


    Buy from Centurion


    Select the Form2.vb Screen tab located at the top of the design window, or double-click in a blank area of Form 2 to bring up the Form2 Code View Window. Enter the following code:

    Public Class frmChangeName
    
        Private Sub Form2_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
    
            Me.Left = MainForm.Left + MainForm.Width + 50
            Me.Top = MainForm.Top
            Me.Height = MainForm.Height
    
            Me.AcceptButton = btnAccept
            Me.ActiveControl = txtNewName
    
        End Sub
    
        Private Sub btnAccept_Click(ByVal sender As System.Object, _
    		ByVal e As System.EventArgs) Handles btnAccept.Click
    
            Dim NewName As String
    
            NewName = "Name: " + txtNewName.Text
    
            MainForm.lblPetName.Text = NewName
            txtNewName.Clear()
            txtNewName.Focus()
    
        End Sub
    
    End Class
    						

    Figure MFP-12: Visual Basic Source Code for frmChangeName


    Although the code on these 2 forms isn't very long, there are some very handy tools, that will be beneficial to incorporate in future programs. We'll go through this code right now, and determine what to expect:

    Note: Since following examples download content off the Internet, Centurion is not responsible for any malicious software downloaded by users of this site. The user needs to have the proper security protocols in place before attempting any downloads from the Internet.

    • Private Sub Form1_Load: Since this is the main form, the following events will be executed at program startup.
    • MyDogPicture.Height = 150: This is the height of the picture we are going to download off the site.
    • MyDogPicture.Width = 138: This is the width of the picture we are going to download off the site.
    • MyDogPicture.ImageLocation = "http://centurion2.com/HTML/Tutorial/Dog3.JPG":
      • MyDogPicture: This is the name of the Visual Basic Picture Control that will receive the image file.
      • .ImageLocation: This is where Visual Basic needs to look for the file.
        • Note - This can be a web address or a local file on your own computer system.
      • "http://centurion2.com/HTML/Tutorial/Dog3.JPG": This is the URL on the Centurion Web Site that contains the image.
    • End Sub: End of actions performed when program first executes.

    • Private Sub btnChangeName_Click: Sub executed when Change Name button is pressed.
    • frmChangeName.Show(): Show the ChangeName Form with modeless attributes.
    • End Sub: No further action is response to Change Name button.

    The code associated with Form Change Name is described as follows:

    • Public Class frmChangeName: The code in this window deals with the Change Name form.
    • Private Sub Form2_Load: The following actions will occur immediately after the Change Name Form is displayed:
    • Me.Left=MainForm.Left+MainForm.Width+50: This is to line up the Change Name Form so that both forms are visible.
      • Me.Left: The Left side of the Change Name Form will be located as follows:
      • MainForm.Left+MainForm.Width: Calculation for MainForm.Right.
      • +50: Some arbitrary amount so there is a gap between the two forms.
    • Me.Top=MainForm.Top: Makes the 2 forms parallel with each other.
    • Me.Height=MainForm.Height: Makes the 2 forms about the same size.
    • Me.AcceptButton=btnAccept: Makes the Accept Button respond to the <ENTER> key just like a Mouse Click
    • Me.ActiveControl=txtNewName: Places the cursor in the NewName TextBox.
    • End Sub: End of actions performed when ChangeName Form is displayed.

    • Private Sub btnAccept_Click: Procedure performed when Accept Button is pressed or whenever <ENTER> key is pressed.
    • Dim NewName As String: Container for New Name.
    • NewName="Name: " + txtNewName.Text: Creating New Name from data in TextBox.
    • MainForm.lblPetName.Text=NewName: Transfer NewName to label on MainForm.
      • MainForm: Indicates the recipient of the data transfer is on a different Form.
      • .lblPetName:Control to receive data.
      • .Text: Attribute to be modified.
      • =NewName: The data that is transferred to the Label Control on the MainForm.
    • txtNewName.Clear(): Clear the previous User Input.
    • txtNewName.Focus(): Keep the Focus on the TextBox.

    Well let's give it a whirl, and see if it performs up to expectations. Press the and see if we get some correlation:

    Ex1 @ Runtime 1

    Figure MFP-13: Visual Basic Multiform Project - Example 1 @ Runtime


    Press the Change Name button, to bring up the second form:

    Ex1 @ Runtime 2

    Figure MFP-14: Visual Basic Multiform Project - Example 1 @ Runtime - #2


    Enter the new name you deem appropriate, I chose 'Fang', in the TextBox and press <ENTER> instead of the Accept Button. You should see the corresponding name change on the MainForm as indicated in the diagram below:

    Ex1 @ Runtime 3

    Figure MFP-15: Visual Basic Multiform Project - Example 1 @ Runtime - #3


    Well, there you have it. That is all you need to change the name of your pet. In my case, intruders should now be aware of the danger that lies within and should stay far away. I am just not sure if my wife is going to feel the same way.

    That's it for now. Hopefully, I can get back and continue and cover some more topics before too long. There are many other subjects that need addressing in the short term, check those out if you get the chance. Short term, future suggests that you need to be proficient in Web Programing Techniques, which is the Next link below: Long term, Game and Simulation Hardware/Software development has no end in sight. If you are proficient in these areas, you're going to have to work at being unsuccessful. For now, jump to Web Programming Guide to work on some more advanced programming concepts in the meantime.

    Home


    Visual Basic

    Introduction to VB.NET

    .NET Framework

    VS2008 IDE

    How VB is Compiled

    Start Visual Studio


    Windows Form App


    Save Your Work

    VB OOP Programming

    Visual Basic Code


    Exit Code


    Button Event Code

    Coding Recommendations

    If/Then/Else

    Error List Window

    Comment Syntax

    Help Window

    Language Essentianl

    Built-In Data Types


    Declare Variables

    Declare Constants

    Code Arithmetic Expressions

    Assignment Statements

    Operator Precedence

    Type Casting


    Math Class

    String Declaration

    Conversion Functions

    Conversion Methods

    Formatting Functions

    String Formatting


    Variable Scope

    Enumerations

    Nullable Types


    Loop Constructs

    For Next Loop

    Do While Loop


    Do Until Loop

    Do...Loop-While

    Do...Loop-Until


    Exit Do | Exit For

    Do...Loop


    Nested Loops


    Arrays

    Array Declaration


    Rnd( ) Function

    Listbox Control


    KeyPressEventArgs


    Parallel Arrays

    Key Event Args


    Dynamic Arrays

    Redimension Array

    Set Breakpoint

    Start Debugger


    ReDim Preserve


    MultiDimensional Arrays

    DataGridView Control


    Length and Sort Methods


    Structures

    Pad Right

    Split Method

    IsNumeric Function


    Multiform Projects


    Add Form To Project

    Form Object Methods

    Form Show Method

    ShowDialog Method

    Form Close Method

    Form Accept Button

    Multiform Project Example


    ASP.NET Web Programming

    Create Data Source


    Configure Access Data Source


    Add Product Class


    Extract Local Database Data

    Order PageLoad VB Code

    Add New Web Page


    Set Start Page

    Display Cart Aspx Code

    Display Cart Design View

    Sorted List Definition

    VB.NET Session State


    Create CartItem Class

    GetCartContents Function


    Add To Cart Event Handler

    Remove Cart Item Event


    Clear Cart Event Handler