.NET Practical Slip 22 Q B

Q. Write a VB.NET program to design the following form; it contains three menus: Color (Red, Blue, Green), Window (Maximize, Minimize, Restore), and Exit. On selection of any menu or submenu, the result should affect the form control (for example, if the user selects Red color from the Color menu, the back color of the form should change to Red, and if the user selects Maximize from the Window menu, the form should be maximized). 25 Marks

Answer:

Steps to Design the Form

  1. Create a Windows Forms Application in VB.NET.
  2. Add a MenuStrip control to the form.
  3. Add Color├── Red├── Blue└── Green
  4. Window├── Maximize├── Minimize└── Restore
Public Class Form1

    ' Color Menu Events
    Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedToolStripMenuItem.Click
        Me.BackColor = Color.Red
    End Sub

    Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlueToolStripMenuItem.Click
        Me.BackColor = Color.Blue
    End Sub

    Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GreenToolStripMenuItem.Click
        Me.BackColor = Color.Green
    End Sub

    ' Window Menu Events
    Private Sub MaximizeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MaximizeToolStripMenuItem.Click
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Private Sub MinimizeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MinimizeToolStripMenuItem.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub

    Private Sub RestoreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RestoreToolStripMenuItem.Click
        Me.WindowState = FormWindowState.Normal
    End Sub

    ' Exit Menu Event
    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

End Class
Spread the love

Leave a Comment

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

Scroll to Top