0% found this document useful (0 votes)
50 views8 pages

BCA Menu Implementation Guide

The document discusses menus and dialog boxes in .NET programs. It describes how to add menus using the MainMenu and MenuItem classes. Common menu options like File, New, Clear, Edit, Cut, Copy, and Paste are demonstrated. Code examples are provided to handle menu click events to show/hide controls and call methods like Cut(), Copy(), and Paste() on a RichTextBox. Additional menu options allow opening images and text files using dialog boxes for loading/saving files and setting font/color properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views8 pages

BCA Menu Implementation Guide

The document discusses menus and dialog boxes in .NET programs. It describes how to add menus using the MainMenu and MenuItem classes. Common menu options like File, New, Clear, Edit, Cut, Copy, and Paste are demonstrated. Code examples are provided to handle menu click events to show/hide controls and call methods like Cut(), Copy(), and Paste() on a RichTextBox. Additional menu options allow opening images and text files using dialog boxes for loading/saving files and setting font/color properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter - 7

Menus and Dialog Boxes


Menus
• A program with more few operations can be
benefited by adding menus
• Classes Used in .Net
– System.Windows.Form.MainMenu
– System.Windows.Form.MenuItem
Steps ….
• Select Menu Strip item from the Tool Box
– Place it in the Form
– Add Items just by clicking in the text boxes
For Menus can use only File – new , clear and Edit – Cut, Copy and Paste Options
Coding…
Imports System.IO
Public Class Form8
Private Sub NewToolStripMenuItem_Click
RichTextBox1.Visible = True
End Sub
Private Sub Form8_Load
PictureBox1.Visible = False
RichTextBox1.Visible = False
End Sub
Private Sub ClearToolStripMenuItem_Click
RichTextBox1.Text = ""
End Sub
Private Sub ExitToolStripMenuItem_Click
End
End Sub
Private Sub CutToolStripMenuItem_Click
RichTextBox1.Cut()
End Sub

Private Sub CopyToolStripMenuItem_Click


RichTextBox1.Copy()
End Sub

Private Sub PasteToolStripMenuItem_Click


RichTextBox1.Paste()
End Sub
Private Sub ImageToolStripMenuItem_Click
PictureBox1.Visible = True
RichTextBox1.Visible = False 'to open img files
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel
Then
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If End Sub

Private Sub TextToolStripMenuItem_Click


RichTextBox1.Visible = True PictureBox1.Visible = False
Dim result As DialogResult = OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
Dim path As String = OpenFileDialog1.FileName ' Get the file name.
Dim text As String = File.ReadAllText(path) ' Read in text.
RichTextBox1.Text = text
End If
End Sub
Private Sub SaveToolStripMenuItem_Click
SaveFileDialog1.Filter = "TXT Files (*.txt*)|*.txt"
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
My.Computer.FileSystem.WriteAllText _
(SaveFileDialog1.FileName, RichTextBox1.Text, True)
End If
End Sub
Private Sub FontToolStripMenuItem_Click
If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
RichTextBox1.Font = FontDialog1.Font
End If
End Sub

Private Sub ColorToolStripMenuItem_Click


If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
RichTextBox1.ForeColor = ColorDialog1.Color
End If
End Sub

You might also like