Programble

Free, Open-Source Software Made In Visual Basic

Code Samples

These code samples are written in Visual Basic and C# 2008 programming language. These code samples are free to use, edit, and redistribute.

Draw Grid

        'Insert in form paint handler
        Dim Grid(14, 16) As Rectangle
        Dim x As Integer = -21
        Dim y As Integer = -21
        For i As Integer = 0 To 14
            x += 21
            For i2 As Integer = 0 To 16
                y += 21
                Grid(i, i2).Size = New Size(21, 21)
                Grid(i, i2).X = x
                Grid(i, i2).Y = y
            Next
            y = -21
        Next
        For i As Integer = 0 To 14
            For i2 As Integer = 0 To 16
                e.Graphics.FillRectangle(Brushes.Blue, Grid(i, i2))
                e.Graphics.DrawRectangle(Pens.Yellow, Grid(i, i2))
            Next
        Next

Center Control In Form

 VB:

'Horizontal
Control.Left = (Form.Width / 2) - (Control.Width / 2)
'Vertical
Control.Top = (Form.height / 2) - (Control.height / 2)

C#:

//Horizantal
control.Left = (form.Width / 2) - (control.Width / 2);
//Vertical
control.Top = (form.Height / 2) - (control.Height / 2);

Corner Form

 VB:

    Enum CornerOfScreen
        BottomRight
        BottomLeft
        TopRight
        TopLeft
   
End Enum

 

        With Form
           
Select Case Corner
               
Case CornerOfScreen.BottomRight
                    .Top =
My.Computer.Screen.WorkingArea.Bottom - .Height
                    .Left =
My.Computer.Screen.WorkingArea.Right - .Width
               
Case CornerOfScreen.BottomLeft
                    .Top =
My.Computer.Screen.WorkingArea.Bottom - .Height
                    .Left =
My.Computer.Screen.WorkingArea.Left
               
Case CornerOfScreen.TopRight
                    .Top =
My.Computer.Screen.WorkingArea.Top
                    .Left =
My.Computer.Screen.WorkingArea.Right - .Width
               
Case CornerOfScreen.TopLeft
                    .Top =
My.Computer.Screen.WorkingArea.Top
                    .Left =
My.Computer.Screen.WorkingArea.Left
           
End Select
       
End With

Populate A ListBox With Files/Folders

 VB:

With My.Computer.FileSystem
    For Each itm As String In .GetDirectories({Directory})
        ListBox1.Items.Add(itm.Replace({Directory} & "\", "")).Tag = "Dir"
    Next
    For Each itm As String In .GetFiles(
{Directory})
        ListBox1.Items.Add(itm.Replace(
{Directory} & "\", "")).Tag = "File"
    Next 
End With 

Populate A ListBox With Installed Fonts

 VB:

For Each ff As FontFamily In FontFamily.Families   
   
ListBox1.Items.Add(ff.Name)
Next

C#:

foreach (FontFamily ff in FontFamily.Families)
{
    listBox1.Items.Add(ff.Name);
}