'SW-403 Final
Exam
'GUILLERMO JULCA
'Click here to get the Final Exam (PDF format)

Public Class
frmMainLanguages
Inherits System.Windows.Forms.Form
Dim arrPhrases(5)
As String 'Static Global
array to store the phrases for the different languages
Dim arrFlags(5)
As String 'Static array
to store the name of the files for the different countries flags
#Region
" Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is
required by the Windows Form Designer.
InitializeComponent()
'Add any
initialization after the InitializeComponent() call
End Sub
'Form overrides
dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If
disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End
If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the
Windows Form Designer
Private
components As System.ComponentModel.IContainer
'NOTE: The
following procedure is required by the Windows Form Designer
'It can be
modified using the Windows Form Designer.
'Do not modify it
using the code editor.
Friend WithEvents lstCountries As System.Windows.Forms.ListBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lblDisplaySentence As System.Windows.Forms.Label
Friend WithEvents pctShowFlag As System.Windows.Forms.PictureBox
Friend WithEvents mnuLanguageFlag As System.Windows.Forms.ContextMenu
Friend WithEvents mnuFlagPhraseInvisible As System.Windows.Forms.MenuItem
Friend WithEvents mnuFlagToAnotherForm As System.Windows.Forms.ContextMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim
resources As System.Resources.ResourceManager
= New System.Resources.ResourceManager(GetType(frmMainLanguages))
Me.lstCountries = New
System.Windows.Forms.ListBox
Me.Label1
= New System.Windows.Forms.Label
Me.lblDisplaySentence = New System.Windows.Forms.Label
Me.pctShowFlag = New
System.Windows.Forms.PictureBox
Me.mnuFlagToAnotherForm = New System.Windows.Forms.ContextMenu
Me.MenuItem1
= New System.Windows.Forms.MenuItem
Me.mnuLanguageFlag = New
System.Windows.Forms.ContextMenu
Me.mnuFlagPhraseInvisible = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
'
'lstCountries
'
Me.lstCountries.Items.AddRange(New Object() {"Danish", "Dutch",
"French", "German", "Italian",
"Spanish"})
Me.lstCountries.Location = New System.Drawing.Point(40, 96)
Me.lstCountries.Name = "lstCountries"
Me.lstCountries.Size = New System.Drawing.Size(112, 108)
Me.lstCountries.TabIndex = 0
'
'Label1
'
Me.Label1.Location
= New System.Drawing.Point(40, 64)
Me.Label1.Name
= "Label1"
Me.Label1.Size
= New System.Drawing.Size(120, 24)
Me.Label1.TabIndex
= 1
Me.Label1.Text
= "Pick a Language:"
'
'lblDisplaySentence
'
Me.lblDisplaySentence.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.lblDisplaySentence.ForeColor = System.Drawing.Color.Blue
Me.lblDisplaySentence.Location = New System.Drawing.Point(192, 240)
Me.lblDisplaySentence.Name = "lblDisplaySentence"
Me.lblDisplaySentence.Size = New System.Drawing.Size(264, 16)
Me.lblDisplaySentence.TabIndex = 2
'
'pctShowFlag
'
Me.pctShowFlag.ContextMenu = Me.mnuFlagToAnotherForm
Me.pctShowFlag.Image = CType(resources.GetObject("pctShowFlag.Image"), System.Drawing.Image)
Me.pctShowFlag.Location = New System.Drawing.Point(192, 72)
Me.pctShowFlag.Name = "pctShowFlag"
Me.pctShowFlag.Size = New
System.Drawing.Size(200, 128)
Me.pctShowFlag.TabIndex = 3
Me.pctShowFlag.TabStop = False
'
'mnuFlagToAnotherForm
'
Me.mnuFlagToAnotherForm.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index
= 0
Me.MenuItem1.Text
= "Go to Random Windows Form"
'
'mnuLanguageFlag
'
Me.mnuLanguageFlag.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.mnuFlagPhraseInvisible})
'
'mnuFlagPhraseInvisible
'
Me.mnuFlagPhraseInvisible.Index = 0
Me.mnuFlagPhraseInvisible.Text = "Make
the flag and phrase invisible"
'
'frmMainLanguages
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New
System.Drawing.Size(544, 293)
Me.ContextMenu = Me.mnuLanguageFlag
Me.Controls.Add(Me.pctShowFlag)
Me.Controls.Add(Me.lblDisplaySentence)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lstCountries)
Me.Name = "frmMainLanguages"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Hello, how are you in different
languages..."
Me.ResumeLayout(False)
End Sub
#End
Region
Private Sub lstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCountries.SelectedIndexChanged
pctShowFlag.Visible
= True
lblDisplaySentence.Visible
= True
Call DisplayPhrase(lstCountries.SelectedIndex)
Call DisplayFlag(lstCountries.SelectedIndex)
End Sub
Private Sub frmMainLanguages_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'To
initialize global arrays
'To
initialize array of phrases
arrPhrases(0) = "Hej, hvordan har du
det?" 'Danish
arrPhrases(1) = "Hello hoe u bent?" 'Dutch
arrPhrases(2) = "Bonjour comment allez vous?" 'French
arrPhrases(3) = "Hallo, wie geht es Ihnen?" 'German
arrPhrases(4) = "Ciao come siete?" 'Italian
arrPhrases(5) = "¿Hola
cómo esta usted?" 'Spanish
'To
initialize array of flag's file names
arrFlags(0) = "DanishFlag.jpg"
arrFlags(1) = "DutchFlag.jpg"
arrFlags(2) = "FrenchFlag.jpg"
arrFlags(3) = "GermanFlag.jpg"
arrFlags(4) = "ItalianFlag.jpg"
arrFlags(5) = "SpanishFlag.jpg"
'To
initialize list box
lstCountries.SelectedIndex
= 5
'To
initialize the picture with the flag for index 5
pctShowFlag.Image
= Image.FromFile(arrFlags(5))
'To
initialize the text file for the phrase with index 5
lblDisplaySentence.Text
= arrPhrases(5)
End Sub
Private Sub DisplayPhrase(ByVal
intIndex As Integer)
'Subroutine
to display the phrase for the selected country
Select Case intIndex ' Evaluate intIndex.
Case
0 ' Danish
Phrase
lblDisplaySentence.Text
= arrPhrases(0)
Case
1 ' Dutch
Phrase
lblDisplaySentence.Text
= arrPhrases(1)
Case
2 ' French
Phrase
lblDisplaySentence.Text
= arrPhrases(2)
Case
3 ' German
Phrase
lblDisplaySentence.Text
= arrPhrases(3)
Case
4 ' Italian
Phrase
lblDisplaySentence.Text
= arrPhrases(4)
Case
5 ' Spanish
Phrase
lblDisplaySentence.Text
= arrPhrases(5)
End Select
End Sub
Private Sub DisplayFlag(ByVal
intIndex As Integer)
'Subroutine
to display the flag for the selected country
Select Case intIndex ' Evaluate intIndex.
Case
0 ' Danish
Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(0))
Case
1 ' Dutch Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(1))
Case
2 ' French
Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(2))
Case
3 ' German
Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(3))
Case
4 ' Italian
Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(4))
Case
5 ' Spanish
Flag
pctShowFlag.Image
= Image.FromFile(arrFlags(5))
End Select
End Sub
Private Sub mnuFlagPhraseInvisible_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles mnuFlagPhraseInvisible.Click
'Context Menu
to make invisible the flag and phrase
pctShowFlag.Visible
= False
lblDisplaySentence.Visible
= False
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
'Context menu
to bring up the second form with random number generator
Dim objfrmRandomForm As New frmRandomNumber
objfrmRandomForm.ShowDialog()
End Sub
End Class

Public Class
frmRandomNumber
Inherits System.Windows.Forms.Form
Dim intRandomNumber As Integer 'Global variable to store the random number between 1 and
10 generated for the system
Dim intSquareRandomNumber As Integer 'Global variable to store the square value of the random number
Dim sngBarWidth As Single
'Global variable to store the Bar width of the
square value of the random number
Dim sngBarHeight As Single
'Global variable to store the Bar height.Note: it should be equal to the panel height
#Region
" Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is
required by the Windows Form Designer.
InitializeComponent()
'Add any
initialization after the InitializeComponent() call
End Sub
'Form overrides
dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If
disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End
If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the
Windows Form Designer
Private
components As System.ComponentModel.IContainer
'NOTE: The
following procedure is required by the Windows Form Designer
'It can be
modified using the Windows Form Designer.
'Do not modify it
using the code editor.
Friend WithEvents lblRandomNumber As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lblSquareOfRandomNumber As System.Windows.Forms.Label
Friend WithEvents myTimer As System.Windows.Forms.Timer
Friend WithEvents pnlSquareBar As System.Windows.Forms.Panel
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New
System.ComponentModel.Container
Me.lblRandomNumber = New
System.Windows.Forms.Label
Me.Label1
= New System.Windows.Forms.Label
Me.lblSquareOfRandomNumber = New System.Windows.Forms.Label
Me.myTimer = New
System.Windows.Forms.Timer(Me.components)
Me.pnlSquareBar = New
System.Windows.Forms.Panel
Me.Label2
= New System.Windows.Forms.Label
Me.Label3
= New System.Windows.Forms.Label
Me.SuspendLayout()
'
'lblRandomNumber
'
Me.lblRandomNumber.BackColor = System.Drawing.Color.FromArgb(CType(192,
Byte), CType(255, Byte),
CType(192, Byte))
Me.lblRandomNumber.Font = New System.Drawing.Font("Microsoft Sans Serif", 40.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.lblRandomNumber.Location = New System.Drawing.Point(24, 32)
Me.lblRandomNumber.Name = "lblRandomNumber"
Me.lblRandomNumber.Size = New System.Drawing.Size(88, 88)
Me.lblRandomNumber.TabIndex = 0
Me.lblRandomNumber.Text = "9"
Me.lblRandomNumber.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label1
'
Me.Label1.Location
= New System.Drawing.Point(144, 24)
Me.Label1.Name
= "Label1"
Me.Label1.Size
= New System.Drawing.Size(192, 24)
Me.Label1.TabIndex
= 1
Me.Label1.Text
= "The square of the random number is:"
'
'lblSquareOfRandomNumber
'
Me.lblSquareOfRandomNumber.Location = New System.Drawing.Point(344, 24)
Me.lblSquareOfRandomNumber.Name = "lblSquareOfRandomNumber"
Me.lblSquareOfRandomNumber.Size = New System.Drawing.Size(32, 24)
Me.lblSquareOfRandomNumber.TabIndex = 2
Me.lblSquareOfRandomNumber.Text =
"81"
'
'myTimer
'
'
'pnlSquareBar
'
Me.pnlSquareBar.BackColor = System.Drawing.Color.White
Me.pnlSquareBar.Location = New System.Drawing.Point(144, 104)
Me.pnlSquareBar.Name = "pnlSquareBar"
Me.pnlSquareBar.Size = New System.Drawing.Size(400, 24)
Me.pnlSquareBar.TabIndex = 3
'
'Label2
'
Me.Label2.Location
= New System.Drawing.Point(144, 80)
Me.Label2.Name
= "Label2"
Me.Label2.Size
= New System.Drawing.Size(24, 16)
Me.Label2.TabIndex
= 4
Me.Label2.Text
= "0 ->"
'
'Label3
'
Me.Label3.Location
= New System.Drawing.Point(520, 80)
Me.Label3.Name
= "Label3"
Me.Label3.Size
= New System.Drawing.Size(24, 16)
Me.Label3.TabIndex
= 5
Me.Label3.Text
= "100"
'
'frmRandomNumber
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New
System.Drawing.Size(592, 189)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.pnlSquareBar)
Me.Controls.Add(Me.lblSquareOfRandomNumber)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lblRandomNumber)
Me.Name = "frmRandomNumber"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Random number and graphical
display"
Me.ResumeLayout(False)
End Sub
#End
Region
Private Sub frmRandomNumber_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'To
initialize the bar height
sngBarHeight
= pnlSquareBar.Height
Call UpdateObjectsRandomly()
' Sets the timer
interval to 0.5 second = 500 milliseconds.
myTimer.Interval
= 500
myTimer.Start()
End Sub
Private Sub UpdateObjectsRandomly()
'Subroutine
to generate the random number and its square value
'This subroutine
will use these values to update our objects
Randomize() ' Initialize random-number generator.
intRandomNumber
= CInt(Int((10 * Rnd()) + 1)) ' Generate random value between 1 and 10.
lblRandomNumber.Text
= CStr(intRandomNumber)
intSquareRandomNumber
= Math.Pow(intRandomNumber,
2) 'To get the square of the random number generated
lblSquareOfRandomNumber.Text() = CStr(intSquareRandomNumber)
'To get the
bar width randomly in function of the square of the number
'Using simple
math proportions BarWidth/panelWidth =
RandomBarWidth/100
sngBarWidth
= (intSquareRandomNumber / 100) * pnlSquareBar.Width
End Sub
Private Sub myTimer_Tick(ByVal
sender As System.Object,
ByVal e As System.EventArgs) Handles myTimer.Tick
Call UpdateObjectsRandomly()
pnlSquareBar.Invalidate()
End Sub
Private Sub pnlSquareBar_Paint(ByVal sender As
System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlSquareBar.Paint
Dim myBar As RectangleF
Dim myBrush As SolidBrush
'To set our
bar rectangle
myBar
= New RectangleF(0, _
0, _
sngBarWidth, _
sngBarHeight)
'To Draw Bar
Rectangle in the panel.
myBrush
= New SolidBrush(Color.Blue)
e.Graphics.FillRectangle(myBrush, myBar)
End Sub
End Class