Showing posts with label Informational. Show all posts
Showing posts with label Informational. Show all posts

Monday, February 14, 2011

Selecting items in a listbox

This code will show how to select items in a listbox

Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim shirt, pants, shoes As String 
shirt = "shirt"
pants = "pants"
shoes = "shoes"


Me.Close()
End Sub ClassMe.lstTotalItems.Items.Add(shirt)Me.lstTotalItems.Items.Add(pants)Me.lstTotalItems.Items.Add(shoes)Me.lstTotalItems.ScrollAlwaysVisible = TrueEnd Sub
lstTotalItems.SelectedItem = Private Sub btnItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem1.Click"shirt"End Sub
lstTotalItems.SelectedItem = Private Sub btnItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem2.Click"pants"End Sub
lstTotalItems.SelectedItem = Private Sub btnItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem3.Click"shoes"End Sub 



EndPrivate Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Adding Items to a listbox

This code will demonstrate how to add items and select them in a listbox

 Public Class Form1
  
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
     Dim shirt, pants, shoes As String
  
     Shirt = "shirt"
  
     pants = "pants"
  
     shoes = "shoes"
  
     Me.lstTotalItems.Items.Add(shirt)
  
     Me.lstTotalItems.Items.Add(pants)
  
     Me.lstTotalItems.Items.Add(shoes)
  
     Me.lstTotalItems.ScrollAlwaysVisible = True
  
   End Sub
  
   Private Sub btnItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem1.Click
  
     lstTotalItems.SelectedItem = "shirt"
  
   End Sub
  
   Private Sub btnItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem2.Click
  
     lstTotalItems.SelectedItem = "pants"
  
   End Sub
  
   Private Sub btnItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem3.Click
  
     lstTotalItems.SelectedItem = "shoes"
  
   End Sub
  
   Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  
     Me.Close()
  
   End Sub
  
 End Class
  

Adding Buttons and labels programmatically ...

This code shows how to add textboxes and labels and set their location background color etc...

  Public Class Form1
  
 Dim lbl1, lbl2, lbl3 As New Label
  
 Dim WithEvents txt1, txt2, txt3 As New TextBox
  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
 lbl1.Text = "Hello"
  
 lbl1.Location = New Point(8, 163)  
 lbl2.AutoSize = true
  
 Me.Controls.Add(lbl1)
  
 lbl2.Text = "Press the reset button"
  
 lbl2.Location = (123, 5)
  
 lbl3.AutoSize = true
  
  Me.Controls.Add(lbl2)
  
 lbl3.Text = "Live life "
  
 lbl3.Location = New Point(5, 236)True
  
 txt1.Location =New Point(1, 6)
  
  txt1.Name ="txt1"
  
  Me.Controls.Add(lbl3)
  
 Me.Controls.Add(txt1)" 
  
  txt2.Location =New Point(65, 6)
  
  txt2.Name =)"txt2" 
  
  txt3.Location = New Point(124, 240) 
  
 txt3.Name ="txt3" 
  
  Me.Controls.Add(txt2)
  
 New Point(54, 166)   
  
 Me.Controls.Add(txt3) 
  
  
  
 End Sub 
  
 End Class
  

Manipulationg Buttons and Textboxes

This code will manipulate a textbox on a form

 Public Class Form1
  
   Private Sub btnBackGroundColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackgroundColor.Click
  
     'This changes the text colors back and forth between tomato and white
  
     If txtOutputbox.BackColor = Color.White Then
  
       txtOutputbox.BackColor = Color.Tomato
  
     Else
  
       txtOutputbox.BackColor = Color.White
  
     End If
  
   End Sub
  
   Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  
     'Enables the textbox
  
     If txtOutputbox.Enabled = False Then
  
       txtOutputbox.Enabled = True
  
     Else
  
       txtOutputbox.Enabled = False
  
     End If
  
   End Sub
  
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  
     'This one it the same as the two above.
  
     If txtOutputbox.BorderStyle = BorderStyle.Fixed3D Then
  
       txtOutputbox.BorderStyle = BorderStyle.None
  
     Else
  
       txtOutputbox.BorderStyle = BorderStyle.Fixed3D
  
     End If
  
   End Sub
  
   Private Sub btnText_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
  
     If txtOutputbox.Text = "If heaven was a mile away" Then
  
       txtOutputbox.Text = " "
  
     Else
  
       txtOutputbox.Text = "If heaven was a mile away"
  
     End If
  
   End Sub
  
 End Class
  

in this post i will Show how manipulate events on a button

These lines of code will change the location of the button.

Public Class Form1Dim var As Integer 

var += 1
LblCounter.Text = var
Private Sub form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ClickEnd Sub



Private Sub button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnterDim p1 As New Point(52, 214) 'changes the point of the button when the mouuse is entered Dim p2 As New Point(227, 10)If Button1.Location = p1 Then  'if the buttons location doesnt equal the 1st point then the second locations is enabledButton1.Location = p2
ElseButton1.Location = p1 ' (Else If) the point goes back to the 1st point
End If 
 

End
End Sub Class

Sunday, January 16, 2011

Bloggers Everywhere

Is there a way to import live wall papers