Sie sind auf Seite 1von 18

Continue.

Context Menu Input Box Message Box Formatting Display

Create a form Name it as frmContextMenu with caption on your form Context Menu Add a ContextMenuStrip component at your toolbox Type &Color for the 1st menu item, &Font for the 2nd menu item and E&xit for the 3rd menu item

Add a lblMessage to your form and set the Text property to Right Click for the Context Menu Set the forms property to Context Menu Property to ContextMenuStrip1. Add a ColorDialog and Font Dialog component to the form

Public Class frmContextMenu


Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click With ColorDlg 'initialize the dialog box .Color = Me.ForeColor .ShowDialog() 'assign new color Me.ForeColor = .Color End With End Sub Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click With FontDlg 'initialize the dialog box .Font = lblMsg.Font .ShowDialog() 'assign new font lblMsg.Font = .Font End With End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click 'terminate the project End Sub End Class

Done!!! You have successfully done your context menuCongrats.

Create your own context menu by putting OpenFileDialog and SaveFileDialog. Lets try and enjoy the journey

To create input Box you must put a button and write the code as given below: declare variable to get the value from inputbox Dim nama As String assign variable with input box nama = InputBox("Masukkan Nama Anda", "Input Nama") display message at lblmessage using variable from the input box lblMessage.Text = "Nama anda ialah " & nama

Create a

General Form MessageBox.Show(Text) MessageBox.Show(Text,Title) MessageBox.Show(Text,Title,Button) MessageBox.Show(Text,Title,Button,Icon)

Before creating a Message Box you must create a button and write the code appropriately based on the example given.

MessageBox.Show(Text) MessageBox.Show("Ini contoh untuk paparan mesej sahaja") Output:

MessageBox.Show(Text,Title) MessageBox.Show("Ini contoh untuk paparan mesej dan Tajuk", "Mesej") Output:

MessageBox.Show(Text,Title,Button) MessageBox.Show("Ini contoh untuk paparan mesej dan Tajuk dan Button Yes dan No","Mesej", MessageBoxButtons.YesNo) Output:

MessageBox.Show(Text,Title,Button,Icon) MessageBox.Show("Ini contoh untuk paparan mesej dan Tajuk dan Button OK dan CANCEL dan Icon Information", "Mesej", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) Output:

MessageBox Button
MessageBoxButtons.OK MessageBoxButtons.OKCancel MessageBoxButtons.YesNo MessageBoxButtons.YesNoCancel MessageBoxButtons.RetryCancel MessageBoxButtons.AbortRetryIgn ore

Output

MessageBox Button
MessageBoxIcon.Asterisk / MessageBoxIcon.Information / MessageBoxIcon.Stop MessageBoxIcon.Error / MessageBoxIcon.Warning MessageBoxIcon.Exclamation MessageBoxIcon.Question

Output

Write the code based on the output given using Message Box

Das könnte Ihnen auch gefallen