Programming Examples in VB.net

File Manipulation Examples

Operating System Examples

How to package a VB.NET application to run on a different computer

Windows Forms

TextBoxes

Simultaneous update of textboxes (Event-Handlers, module-level variables)

When the content of any one textbox is modified, the other related textboxes are updated instantly.

Timer

Timer Resolution Test (Timer, Sleep, TimeSpan)

A test program to experiment with the resolution of timer in VB.NET. The TimeSpan structure is used in the program. Timer errors are calculated and displayed.

Recursive Procedures

Make Password

An application using recursive procedures to generate passwords from a given pool of letters.

Match Colour Game

Match Colours(Random Numbers, Colours, numeric-up-downs)

An application to test your colour observation skills, at the same time understand how to compose different colours.

UpperCase or Alphanumeric data entry

keypress (KeyPress, EventHandler, IsLetter(), ToUpper())

An example to modify characters entered by the keyboard in a textbox.

Combined Font Styles

How to combine two font styles in the definition of a new font?

In the definition of a new font, there is only one argument for font style to enter multiple attributes such as Bold and Italic. Fortunately FontStyle values are not enumeration constants, but belong to the flagsAttribute Class, which allows the addition of two properties with the OR keyword. For example, if a button is made to change the selected text of RichTextBox1 into ARIAL, 16 points, bold and italic, you could use the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim text1 As String = RichTextBox1.Text
    RichTextBox1.SelectionFont = New Font("ARIAL", 16, FontStyle.Italic Or FontStyle.Bold)
  End Sub
Bold and Italic

Resizable TextBox

How to make a TextBox that you can resize at run time?

With TextBoxR which you can add to your normal toolbox, you can resize and move your TextBox at run time while the alt-key is depressed. Everything else works just like the MicroSoft TextBox from which it was inherited. TextBoxR

Array of Controls

How to create and initialize an array of control, programatically?

If you need to have an array of controls, but are tired of coding each and every one individually:

txtB1.text="Box1"
txtB2.text="Box2"
...

You could try the following code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim txtQ(25) As TextBox
    Dim i As Integer
    For i = 0 To 24
      txtQ(i) = New TextBox()
      Controls.Add(txtQ(i))
      txtQ(i).Top = Math.Floor(i / 5) * 30
      txtQ(i).Left = (i Mod 5) * 50
      txtQ(i).Width = 45
      txtQ(i).Text = "Box " & i.ToString()
    Next

End Sub

Array of TextBoxes


updated 2004-09-24