API Samples

Page 1 of 2
  1. Windows Form Designer generated code
  2. The Code

Windows Form Designer generated code

This sample shows samples of how to use different kinds of APIs. Changing and getting different system settings such as mouse position, beep length and frequency, computer name, user name, drive type, swap mouse button. You will need to create the needed controls on the form before accessing them in code of course. Below is the "Windows Form Designer generated code" region, which will create the controls for you. The "interesting" source code is on the next page!

   Public Sub New()
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents btnUserName As System.Windows.Forms.Button
   Friend WithEvents btnComputerName As System.Windows.Forms.Button
   Friend WithEvents btnExit As System.Windows.Forms.Button
   Friend WithEvents btnGetMouseX As System.Windows.Forms.Button
   Friend WithEvents lblMouseX As System.Windows.Forms.Label
   Friend WithEvents btnGetMouseY As System.Windows.Forms.Button
   Friend WithEvents lblMouseY As System.Windows.Forms.Label
   Friend WithEvents btnDriveType As System.Windows.Forms.Button
   Friend WithEvents txtDrive As System.Windows.Forms.TextBox
   Friend WithEvents btnSwapMouse As System.Windows.Forms.Button
   Friend WithEvents btnResetMouse As System.Windows.Forms.Button
   Friend WithEvents chkNormalMouseOnExit As System.Windows.Forms.CheckBox
   Friend WithEvents trkBeepFreq As System.Windows.Forms.TrackBar
   Friend WithEvents trkBeepLength As System.Windows.Forms.TrackBar
   Friend WithEvents lblBeepFreq As System.Windows.Forms.Label
   Friend WithEvents lblBeepLength As System.Windows.Forms.Label
   Friend WithEvents btnBeep As System.Windows.Forms.Button
   Friend WithEvents lblHz As System.Windows.Forms.Label
   Friend WithEvents lblMs As System.Windows.Forms.Label
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnUserName = New System.Windows.Forms.Button()
       Me.btnComputerName = New System.Windows.Forms.Button()
       Me.btnExit = New System.Windows.Forms.Button()
       Me.btnGetMouseX = New System.Windows.Forms.Button()
       Me.lblMouseX = New System.Windows.Forms.Label()
       Me.btnGetMouseY = New System.Windows.Forms.Button()
       Me.lblMouseY = New System.Windows.Forms.Label()
       Me.btnDriveType = New System.Windows.Forms.Button()
       Me.txtDrive = New System.Windows.Forms.TextBox()
       Me.btnSwapMouse = New System.Windows.Forms.Button()
       Me.btnResetMouse = New System.Windows.Forms.Button()
       Me.chkNormalMouseOnExit = New System.Windows.Forms.CheckBox()
       Me.trkBeepFreq = New System.Windows.Forms.TrackBar()
       Me.trkBeepLength = New System.Windows.Forms.TrackBar()
       Me.lblBeepFreq = New System.Windows.Forms.Label()
       Me.lblBeepLength = New System.Windows.Forms.Label()
       Me.btnBeep = New System.Windows.Forms.Button()
       Me.lblHz = New System.Windows.Forms.Label()
       Me.lblMs = New System.Windows.Forms.Label()
       CType(Me.trkBeepFreq, System.ComponentModel.ISupportInitialize).BeginInit()
       CType(Me.trkBeepLength, System.ComponentModel.ISupportInitialize).BeginInit()
       Me.SuspendLayout()
       '
       'btnUserName
       '
       Me.btnUserName.Location = New System.Drawing.Point(16, 16)
       Me.btnUserName.Name = "btnUserName"
       Me.btnUserName.Size = New System.Drawing.Size(112, 24)
       Me.btnUserName.TabIndex = 0
       Me.btnUserName.Text = "Show UserName"
       '
       'btnComputerName
       '
       Me.btnComputerName.Location = New System.Drawing.Point(144, 16)
       Me.btnComputerName.Name = "btnComputerName"
       Me.btnComputerName.Size = New System.Drawing.Size(136, 24)
       Me.btnComputerName.TabIndex = 1
       Me.btnComputerName.Text = "Show ComputerName"
       '
       'btnExit
       '
       Me.btnExit.Location = New System.Drawing.Point(208, 320)
       Me.btnExit.Name = "btnExit"
       Me.btnExit.Size = New System.Drawing.Size(96, 24)
       Me.btnExit.TabIndex = 2
       Me.btnExit.Text = "E&xit"
       '
       'btnGetMouseX
       '
       Me.btnGetMouseX.Location = New System.Drawing.Point(32, 56)
       Me.btnGetMouseX.Name = "btnGetMouseX"
       Me.btnGetMouseX.Size = New System.Drawing.Size(112, 24)
       Me.btnGetMouseX.TabIndex = 3
       Me.btnGetMouseX.Text = "Get cursor X"
       '
       'lblMouseX
       '
       Me.lblMouseX.Location = New System.Drawing.Point(32, 88)
       Me.lblMouseX.Name = "lblMouseX"
       Me.lblMouseX.Size = New System.Drawing.Size(112, 16)
       Me.lblMouseX.TabIndex = 4
       Me.lblMouseX.Text = "X: Press Get"
       '
       'btnGetMouseY
       '
       Me.btnGetMouseY.Location = New System.Drawing.Point(160, 56)
       Me.btnGetMouseY.Name = "btnGetMouseY"
       Me.btnGetMouseY.Size = New System.Drawing.Size(104, 24)
       Me.btnGetMouseY.TabIndex = 5
       Me.btnGetMouseY.Text = "Get cursor Y"
       '
       'lblMouseY
       '
       Me.lblMouseY.Location = New System.Drawing.Point(160, 88)
       Me.lblMouseY.Name = "lblMouseY"
       Me.lblMouseY.Size = New System.Drawing.Size(104, 16)
       Me.lblMouseY.TabIndex = 6
       Me.lblMouseY.Text = "Y: Press Get"
       '
       'btnDriveType
       '
       Me.btnDriveType.Location = New System.Drawing.Point(88, 120)
       Me.btnDriveType.Name = "btnDriveType"
       Me.btnDriveType.Size = New System.Drawing.Size(104, 24)
       Me.btnDriveType.TabIndex = 7
       Me.btnDriveType.Text = "Get Drive Type"
       '
       'txtDrive
       '
       Me.txtDrive.Location = New System.Drawing.Point(200, 120)
       Me.txtDrive.MaxLength = 1
       Me.txtDrive.Name = "txtDrive"
       Me.txtDrive.Size = New System.Drawing.Size(24, 21)
       Me.txtDrive.TabIndex = 8
       Me.txtDrive.Text = "C"
       '
       'btnSwapMouse
       '
       Me.btnSwapMouse.Location = New System.Drawing.Point(8, 280)
       Me.btnSwapMouse.Name = "btnSwapMouse"
       Me.btnSwapMouse.Size = New System.Drawing.Size(120, 24)
       Me.btnSwapMouse.TabIndex = 9
       Me.btnSwapMouse.Text = "Swap Mouse Buttons"
       '
       'btnResetMouse
       '
       Me.btnResetMouse.Location = New System.Drawing.Point(136, 280)
       Me.btnResetMouse.Name = "btnResetMouse"
       Me.btnResetMouse.Size = New System.Drawing.Size(168, 24)
       Me.btnResetMouse.TabIndex = 10
       Me.btnResetMouse.Text = "Return Mouse Button Settings"
       '
       'chkNormalMouseOnExit
       '
       Me.chkNormalMouseOnExit.CheckAlign = System.Drawing.ContentAlignment.BottomRight
       Me.chkNormalMouseOnExit.Location = New System.Drawing.Point(32, 320)
       Me.chkNormalMouseOnExit.Name = "chkNormalMouseOnExit"
       Me.chkNormalMouseOnExit.Size = New System.Drawing.Size(168, 16)
       Me.chkNormalMouseOnExit.TabIndex = 11
       Me.chkNormalMouseOnExit.Text = "Normalize my mouse on exit"
       '
       'trkBeepFreq
       '
       Me.trkBeepFreq.Location = New System.Drawing.Point(56, 144)
       Me.trkBeepFreq.Maximum = 20
       Me.trkBeepFreq.Name = "trkBeepFreq"
       Me.trkBeepFreq.Orientation = System.Windows.Forms.Orientation.Vertical
       Me.trkBeepFreq.Size = New System.Drawing.Size(45, 104)
       Me.trkBeepFreq.TabIndex = 12
       Me.trkBeepFreq.TickStyle = System.Windows.Forms.TickStyle.Both
       '
       'trkBeepLength
       '
       Me.trkBeepLength.Location = New System.Drawing.Point(208, 144)
       Me.trkBeepLength.Maximum = 20
       Me.trkBeepLength.Name = "trkBeepLength"
       Me.trkBeepLength.Orientation = System.Windows.Forms.Orientation.Vertical
       Me.trkBeepLength.Size = New System.Drawing.Size(45, 104)
       Me.trkBeepLength.TabIndex = 13
       Me.trkBeepLength.TickStyle = System.Windows.Forms.TickStyle.Both
       '
       'lblBeepFreq
       '
       Me.lblBeepFreq.Location = New System.Drawing.Point(32, 248)
       Me.lblBeepFreq.Name = "lblBeepFreq"
       Me.lblBeepFreq.Size = New System.Drawing.Size(120, 16)
       Me.lblBeepFreq.TabIndex = 14
       Me.lblBeepFreq.Text = "Beep Frequency: 0"
       '
       'lblBeepLength
       '
       Me.lblBeepLength.Location = New System.Drawing.Point(192, 248)
       Me.lblBeepLength.Name = "lblBeepLength"
       Me.lblBeepLength.Size = New System.Drawing.Size(104, 16)
       Me.lblBeepLength.TabIndex = 15
       Me.lblBeepLength.Text = "Beep Length: 0"
       '
       'btnBeep
       '
       Me.btnBeep.Location = New System.Drawing.Point(104, 176)
       Me.btnBeep.Name = "btnBeep"
       Me.btnBeep.Size = New System.Drawing.Size(96, 40)
       Me.btnBeep.TabIndex = 16
       Me.btnBeep.Text = "Beep with these settings"
       '
       'lblHz
       '
       Me.lblHz.Location = New System.Drawing.Point(24, 264)
       Me.lblHz.Name = "lblHz"
       Me.lblHz.Size = New System.Drawing.Size(120, 16)
       Me.lblHz.TabIndex = 17
       Me.lblHz.Text = "Cycles per second (Hz)"
       '
       'lblMs
       '
       Me.lblMs.Location = New System.Drawing.Point(192, 264)
       Me.lblMs.Name = "lblMs"
       Me.lblMs.Size = New System.Drawing.Size(96, 16)
       Me.lblMs.TabIndex = 18
       Me.lblMs.Text = "Milliseconds (MS)"
       '
       'frmAPI
       '
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.ClientSize = New System.Drawing.Size(314, 352)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblMs, Me.lblHz, Me.btnBeep, Me.lblBeepLength, Me.lblBeepFreq, Me.trkBeepLength, Me.trkBeepFreq, Me.chkNormalMouseOnExit, Me.btnResetMouse, Me.btnSwapMouse, Me.txtDrive, Me.btnDriveType, Me.lblMouseY, Me.btnGetMouseY, Me.lblMouseX, Me.btnGetMouseX, Me.btnExit, Me.btnComputerName, Me.btnUserName})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
       Me.MaximizeBox = False
       Me.Name = "frmAPI"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
       Me.Text = "APIs for CS54"
       CType(Me.trkBeepFreq, System.ComponentModel.ISupportInitialize).EndInit()
       CType(Me.trkBeepLength, System.ComponentModel.ISupportInitialize).EndInit()
       Me.ResumeLayout(False)

   End Sub

You might also like...

Comments

Matthew Taylor

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay