Menu

VB.NET TUTORIALS - VB.Net - Advanced Forms

VB.Net - Advanced Forms

ADVERTISEMENTS

Adding Menus and Sub Menus in an Application

S.N.Control & Description
1MenuStrip
It provides a menu system for a form.
2ToolStripMenuItem
It represents a selectable option displayed on a MenuStrip or ContextMenuStrip. The ToolStripMenuItem control replaces and adds functionality to the MenuItem control of previous versions.
2ContextMenuStrip
It represents a shortcut menu.

ADVERTISEMENTS

Adding the Cut, Copy and Paste Functionalities in a Form

S.NMethod Name & Description
1Clear
Removes all data from the Clipboard.
2ContainsData
Indicates whether there is data on the Clipboard that is in the specified format or can be converted to that format.
3ContainsImage
Indicates whether there is data on the Clipboard that is in the Bitmap format or can be converted to that format.
4ContainsText
Indicates whether there is data on the Clipboard in the Text or UnicodeText format, depending on the operating system.
5GetData
Retrieves data from the Clipboard in the specified format.
6GetDataObject
Retrieves the data that is currently on the system Clipboard.
7GetImage
Retrieves an image from the Clipboard.
8GetText
Retrieves text data from the Clipboard in the Text or UnicodeText format, depending on the operating system.
9GetText(TextDataFormat)
Retrieves text data from the Clipboard in the format indicated by the specified TextDataFormat value.
10SetData
Clears the Clipboard and then adds data in the specified format.
11SetText(String)
Clears the Clipboard and then adds text data in the Text or UnicodeText format, depending on the operating system.

ADVERTISEMENTS

Adding Menus and Sub Menus in an Application

Public Class Form1
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      'defining the main menu bar
      Dim mnuBar As New MainMenu()
      'defining the menu items for the main menu bar
      Dim myMenuItemFile As New MenuItem("&File")
      Dim myMenuItemEdit As New MenuItem("&Edit")
      Dim myMenuItemView As New MenuItem("&View")
      Dim myMenuItemProject As New MenuItem("&Project")

      'adding the menu items to the main menu bar
      mnuBar.MenuItems.Add(myMenuItemFile)
      mnuBar.MenuItems.Add(myMenuItemEdit)
      mnuBar.MenuItems.Add(myMenuItemView)
      mnuBar.MenuItems.Add(myMenuItemProject)

     ' defining some sub menus
      Dim myMenuItemNew As New MenuItem("&New")
      Dim myMenuItemOpen As New MenuItem("&Open")
      Dim myMenuItemSave As New MenuItem("&Save")

      'add sub menus to the File menu
      myMenuItemFile.MenuItems.Add(myMenuItemNew)
      myMenuItemFile.MenuItems.Add(myMenuItemOpen)
      myMenuItemFile.MenuItems.Add(myMenuItemSave)

      'add the main menu to the form
      Me.Menu = mnuBar
     
      ' Set the caption bar text of the form.  
      Me.Text = ""
   End Sub
End Class

Adding the Cut, Copy and Paste Functionalities in a Form

Public Class Form1
   Private Sub Form1_Load(sender As Object, e As EventArgs) _ 
    Handles MyBase.Load
      ' Set the caption bar text of the form.  
      Me.Text = ""
   End Sub
   Private Sub Button1_Click(sender As Object, e As EventArgs) _ 
      Handles Button1.Click
      Clipboard.SetDataObject(RichTextBox1.SelectedText)
      RichTextBox1.SelectedText = ""
   End Sub
   Private Sub Button2_Click(sender As Object, e As EventArgs) _
       Handles Button2.Click
      Clipboard.SetDataObject(RichTextBox1.SelectedText)
   End Sub
   Private Sub Button3_Click(sender As Object, e As EventArgs) _
    Handles Button3.Click
      Dim iData As IDataObject
      iData = Clipboard.GetDataObject()
      If (iData.GetDataPresent(DataFormats.Text)) Then
          RichTextBox1.SelectedText = iData.GetData(DataFormats.Text)
      Else
          RichTextBox1.SelectedText = " "
      End If
   End Sub
End Class

Modal Forms

Private Sub Form2_Load(sender As Object, e As EventArgs) _
   Handles MyBase.Load
   AcceptButton = Button1
   CancelButton = Button2
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) _
   Handles Button1.Click
   Dim frmSecond As Form2 = New Form2()
   If frmSecond.ShowDialog() = DialogResult.OK Then
      Label2.Text = frmSecond.TextBox1.Text
   End If
End Sub