VB.NET TUTORIALS - VB.Net - Advanced Forms
VB.Net - Advanced Forms
ADVERTISEMENTS
Adding Menus and Sub Menus in an Application
S.N. | Control & Description |
---|---|
1 | MenuStrip It provides a menu system for a form. |
2 | ToolStripMenuItem 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. |
2 | ContextMenuStrip It represents a shortcut menu. |
ADVERTISEMENTS
Adding the Cut, Copy and Paste Functionalities in a Form
S.N | Method Name & Description |
---|---|
1 | Clear Removes all data from the Clipboard. |
2 | ContainsData Indicates whether there is data on the Clipboard that is in the specified format or can be converted to that format. |
3 | ContainsImage Indicates whether there is data on the Clipboard that is in the Bitmap format or can be converted to that format. |
4 | ContainsText Indicates whether there is data on the Clipboard in the Text or UnicodeText format, depending on the operating system. |
5 | GetData Retrieves data from the Clipboard in the specified format. |
6 | GetDataObject Retrieves the data that is currently on the system Clipboard. |
7 | GetImage Retrieves an image from the Clipboard. |
8 | GetText Retrieves text data from the Clipboard in the Text or UnicodeText format, depending on the operating system. |
9 | GetText(TextDataFormat) Retrieves text data from the Clipboard in the format indicated by the specified TextDataFormat value. |
10 | SetData Clears the Clipboard and then adds data in the specified format. |
11 | SetText(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 ClassAdding 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 ClassModal 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