Sunday, February 13, 2011

Programming 2 */ Form Object Manipulation */

1. Create a form with a single button (use the gui for this one). When the button is hovered over, move the button to another part of the form. The button should move back and forth between 2 points. If you want to be special, move the button to a random part of the form. You will have to use a random number generator for the x and y coordinates making sure the random x and y are not larger than the form height and width. If you don't feel like being special, just...
Public Class Form1
   Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.MouseEnter  
     Dim rnd1 As New Random  
     Dim x As Integer = rnd1.Next(150)  
     Dim y As Integer = rnd1.Next(300)  
     Button.Location = New Point(x, y)  
   End Sub  
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.Click  
     MessageBox.Show("You Win")  
   End Sub  
2.
a. Button 2: This button will make the textbox enabled/disabled.
b. Button 3: Turn a background color on the textbox on and off. (Toggle between white and
another color)
c. Button 4: Put text inside of the text box and take it away
d. Button 5: Change the border style of the textbox between none and fixed3d
Create a form with 4 buttons and one text box (use the gui). The button wording should
describe what it does.
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click  
     If TextBox1.Enabled = True Then  
       TextBox1.Enabled = False  
     Else : TextBox1.Enabled = True  
     End If  
   End Sub  
   Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click  
     If TextBox1.BackColor = Color.White Then  
       TextBox1.BackColor = Color.Black  
     Else : TextBox1.BackColor = Color.White  
     End If  
   End Sub  
   Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click  
     If TextBox1.Text = "" Then  
       TextBox1.Text = "HI!!!"  
     Else : TextBox1.Text = ""  
     End If  
   End Sub  
   Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click  
     If TextBox1.BorderStyle = BorderStyle.None Then  
       TextBox1.BorderStyle = BorderStyle.Fixed3D  
     Else : TextBox1.BorderStyle = BorderStyle.None  
     End If  
   End Sub
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 it is not being hovered over, change the background color back to white.
Dim l1, l2, l3 As New Label  
   Dim WithEvents t1, t2, t3 As New TextBox  
   Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click  
     l1.Location = New Point(50, 50)  
     l1.Text = "Label1"  
     l2.Location = New Point(50, 100)  
     l2.Text = "Label2"  
     l3.Location = New Point(50, 150)  
     l3.Text = "Label3"  
     Me.Controls.Add(l1)  
     Me.Controls.Add(l2)  
     Me.Controls.Add(l3)  
     t1.Location = New Point(150, 50)  
     t2.Location = New Point(150, 100)  
     t3.Location = New Point(150, 150)  
     Me.Controls.Add(t1)  
     Me.Controls.Add(t2)  
     Me.Controls.Add(t3)  
   End Sub  
   Private Sub t1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t1.MouseEnter  
     t1.BackColor = Color.Black  
   End Sub  
   Private Sub t2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.MouseEnter  
     t2.BackColor = Color.Black  
   End Sub  
   Private Sub t3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles t3.MouseEnter  
     t3.BackColor = Color.Black  
   End Sub  
   Private Sub t1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t1.MouseLeave  
     t1.BackColor = Color.White  
   End Sub  
   Private Sub t2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.MouseLeave  
     t2.BackColor = Color.White  
   End Sub  
   Private Sub t3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles t3.MouseLeave  
     t3.BackColor = Color.White  
   End Sub
4.
Create a form with 3 buttons and a listbox.
Load 3 items into the listbox on load so that its not empty
Button 1: Select Item 1
Button 2: Select Item 2
Button 3: Select Item 3
Dim WithEvents b1, b2, b3 As New Button  
   Dim lb1 As New ListBox  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
     b1.Location = New Point(300, 140)  
     b2.Location = New Point(300, 170)  
     b3.Location = New Point(300, 200)  
     lb1.Location = New Point(300, 230)  
     b1.Text = "Button 7"  
     b2.Text = "Button 8"  
     b3.Text = "Button 9"  
     Me.Controls.Add(b1)  
     Me.Controls.Add(b2)  
     Me.Controls.Add(b3)  
     Me.Controls.Add(lb1)  
     lb1.Items.Add("You")  
     lb1.Items.Add("are")  
     lb1.Items.Add("annoying!!!")  
   End Sub  
   Private Sub b1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b1.Click  
     lb1.SelectedIndex = 0  
   End Sub  
   Private Sub b2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b2.Click  
     lb1.SelectedIndex = 1  
   End Sub  
   Private Sub b3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b3.Click  
     lb1.SelectedIndex = 2  
   End Sub  
   Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click  
     TextBox1.Text = ""  
     TextBox1.BackColor = Color.White  
     TextBox1.BorderStyle = BorderStyle.Fixed3D  
     TextBox1.Enabled = True  
     t1.Text = ""  
     t2.Text = ""  
     t3.Text = ""  
     Button.Location = New Point(12, 11)  
   End Sub  
   Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click  
     Application.Exit()  
   End Sub  
 End Class  

No comments:

Post a Comment

Classes

Programming II

Advanced Relational Database

Followers