Wednesday, February 16, 2011

Practice #3 - Form Objects

1. Create a form witha single button (use the gui for this one). When the button is hovered over, moe the button to another part of the form. The button should move back and forth between 2 points.
   Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
  
     Dim x As New Point(10, 10)
  
     Dim y As New Point(50, 50)
  
     If Button1.Location = x Then
  
       Button1.Location = y
  
     Else
  
       Button1.Location = x
  
     End If
  
   End Sub
  
 End Class  

2. Create a form with 4 buttons and one text box (use the gui).  The botton wording should describe what it does.
a. Button 1: This button will make the textbox enabled/disabled.
b. Button 2: Turn a background color on the textbox on and off. (Toggle between white and another color)
c. Button 3: Put the text inside of the text box and take it away
d. Button 4: Change the border style of the textbox between none and fixed3D.
 Private Sub btnTxtEnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxtEnDisable.Click
  
 If txtBox.Enabled = True Then
  
 txtBox.Enabled = False
  
 End If
  
 txtBox.Enabled = True
  
 End Sub
  
   Private Sub btnTxtBackColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxtBackColor.Click
  
     If txtBox.BackColor = Color.Blue Then
  
       txtBox.BackColor = Color.White
  
     Else
  
       txtBox.BackColor = Color.Blue
  
     End If
  
   End Sub  

   Private Sub btnTxtErase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxtErase.Click
  
     If txtBox.Text = "Teeps is the man" Then
  
       txtBox.Text = ""
  
     Else
  
       txtBox.Text = "Teeps is the man"
  
     End If
  
   End Sub  

   Private Sub btnTxtBorderStyle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxtBorderStyle.Click
  
     If txtBox.BorderStyle = BorderStyle.None Then
  
       txtBox.BorderStyle = BorderStyle.Fixed3D
  
     Else
  
       txtBox.BorderStyle = BorderStyle.None
  
     End If
  
   End Sub
  
 End Class  

3. Create a form with a button (using the gui). When this button is clicked, it will create 3 labels and 3 textboxes associated with those labels.  When the textboxes are hovered over, change their background color.  When is not being hovered over, change the background color back to white.
 Public Class Form1
  
   Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
     txtFirst.Show()
  
     txtSecond.Show()
  
     txtThird.Show()
  
     lblFirst.Show()
  
     lblSecond.Show()
  
     lblThird.Show()
  
   End Sub
  
   Private Sub txtFirst_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirst.MouseEnter
  
     txtFirst.BackColor = Color.Red
  
   End Sub
  
   Private Sub txtFirst_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirst.MouseLeave
  
     txtFirst.BackColor = Color.White
  
   End Sub
  
   Private Sub txtSecond_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSecond.MouseEnter
  
     txtSecond.BackColor = Color.Yellow
  
   End Sub
  
   Private Sub txtSecond_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSecond.MouseLeave
  
     txtSecond.BackColor = Color.White
  
   End Sub
  
   Private Sub txtThird_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtThird.MouseEnter
  
     txtThird.BackColor = Color.Green
  
   End Sub
  
   Private Sub txtThird_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtThird.MouseLeave
  
     txtThird.BackColor = Color.White
  
   End Sub
  
 End Class  
 
4. Create a form with 3 buttons and a listbox. Load 3 items on load so that it's not empty
Button1: Select Item 1
Button 2: Select Item 2
Button 3: Select Item 3
 Public Class Form1
  
   Dim str1, str2, str3 As String
  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
     str1 = "First is the worst"
  
     str2 = "Second is the best"
  
     str3 = "Third is.....?"
  
     ListBox1.Items.Add(str1)
  
     ListBox1.Items.Add(str2)
  
     ListBox1.Items.Add(str3)
  
   End Sub
  
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  
     ListBox1.SelectedIndex = 0
  
   End Sub
  
   Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  
     ListBox1.SelectedIndex = 1
  
   End Sub
  
   Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
  
     ListBox1.SelectedIndex = 2
  
   End Sub
  
 End Class  

No comments:

Post a Comment