Example : How to create/set Hotkey/Shortcut Key with Button.
- Write ‘&’ symbol before the button name we want to make shortcut in ‘text’ property of 
  property window.To display the effect, press that letter with alt key.(such as &Save- use 
  alt+S)
Example : How to type/display/use ‘&’ Key/letter in VB .net 2013 form.
- Type && to display single & in your form/page at proper place.
Example : How to enable/disable the vb controls.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Enabled = True
        TextBox2.Enabled = False
        Button1.Enabled = True
End Sub
Example : How to hide/unhide the vb controls.
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Hide()
        Button1.Hide()
        DataGridView1.Hide()

        '----------------  OR  ---------------
        Button1.Visible = True
        Button1.Visible = False
 End Sub

NB : VB Controls are by default unhide/visible.
Example : How to make VB controls/box read only ON/OFF.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.ReadOnly = True
        TextBox1.ReadOnly = False
End Sub
Example : How to set focus/cursor in specific VB controls/box.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Focus()
        Button1.Focus()
End Sub
Example : How to make a button toggle [Same button having two job].
If Button1.Text = "Hide" Then
   Button1.Text = "View"
ElseIf Button1.Text = "View" Then
   Button1.Text = "Hide"
Else
   Button1.Text = "Click Me"
End If

'----------------  OR  ---------------
Private Sub BtnShowHideData_Click(ByVal sender As System.Object, ByVal e  As 
    System.EventArgs) Handles BtnShowHideData.Click
       If BtnShowHideData.Text = "&Show Data " Then
           DataGridView1.Visible = True
           BtnShowHideData.Text = " &Hide Data "
       Else
           BtnShowHideData.Text = " &Hide Data "
           DataGridView1.Visible = False
           BtnShowHideData.Text = "&Show Data "
       End If
End Sub

'NB: Single button show two effects/states(toggle),i.e., Show and Hide- here they are used to 
     enable/disable Datagridview1 controls respectively on clicking the button.Here & symbol 
     before the letter makes it highlighted to use with ALT button as shortcut key.
Example : How to get input values from the user through keyboard dynamically.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim str As String = InputBox("Enter Your Name")
        MsgBox(str)

        Dim num As Integer = InputBox("Enter Your Mobile Number")
        MsgBox(num)
End Sub
Example : How to use Calculator in our application in VB .Net 2013.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        
        Dim ts As New System.Security.SecureString
        System.Diagnostics.Process.Start("c:\WINDOWS\system32\calc.exe") 

        ----------------  OR  ---------------

        'Shell("Calc.exe")
End Sub
Example : How to Close/Exit the VB Application.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        
        Application.Exit() 
        ----------------  OR  ---------------
        Me.Close() 
        ----------------  OR  ---------------
        End 
        ----------------  OR  ---------------
        Me.Dispose()
 End Sub
Example : How to Maximize the Form in VB .Net 2013.
First Method: Dynamic or through source code - 

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
     End Sub

----------------  OR  ---------------

Second Method: Static or through Property Window settings -
 
    Select the Form - Property Window - Choose "Maximized" option/attribute from "Window 
    State" property. 
Example : How to disable Maximize symbol of a Form Window.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MaximizeBox = False      
End Sub
Example : How to disable Minimize symbol of a Form Window.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Me.MinimizeBox = False
End Sub
Example : How to disable/remove both Maximize & Minimize symbol of a Form Window.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MaximizeBox = False
        Me.MinimizeBox = False
    End Sub
Example : How to Lock/Unlock all vb controls used on a form.
- Open vb .net application - Design your form with vb controls - click 'Format' menu - choose 
  'Lock Controls' option - Now Vb controls locked.

NB  :To Unlock all the Controls, repeat the same process.
Example : How to Remove Extra Space from a word/sentence.
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim str As String = "      Codershelpline    "
        TextBox1.Text = str.Trim()        
    End Sub
End Class

----------------  OR   -----------------
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim str As New String("      Codershelpline    ")        
        TextBox1.Text = str.Replace(" ", "")
    End Sub
End Class

--------------  OR   ----------------- 
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Dim userName As String = TxtUname.Text.ToString().Trim()
 Dim password As String = TxtPassword.Text.ToString().Trim()

 userName = userName.Trim()
 password = password.Trim()
End Sub
Example : How to Move Cursor in Next Controls/Box on Pressing Enter key.
Private Sub Textbox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TxtVechNo.KeyDown
        If e.KeyCode = Keys.Enter Then
            Textbox2.Focus()
        End If
End Sub
Example : How to Move the Cursor in Next/Previous Controls on Pressing Up & Down                       Arrow Key. [Arrow Key Code]
Private Sub Textbox2_KeyDown(sender As Object, e As KeyEventArgs) Handles TxtVechNo.KeyDown
       If e.KeyCode = Keys.Up Then
            Textbox1.Focus()
       If e.KeyCode = Keys.Down Then
            Textbox3.Focus()
       End If 
End Sub
Example : How to Stop Empty/Blank Box to Save in the database.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        If TextBox1.Text = "" Then
            MsgBox("PLEASE ENTER THE VALUE")
            TextBox1.Focus()
            Exit Sub
        End If

        If Combobox1.Text = "Select One" Then
            MsgBox("PLEASE SELECT THE CHOICE FROM THE LIST")
            Combobox1.Focus()
            Exit Sub
        End If

    End Sub

 424 total views,  2 views today

Categories: VB .Net

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.