Langkah-langkah
untuk mengimplementasikan menu popup diperlihatkan sebagai berikut:
a. Buat sebuah project, lalu tambahkan sebuah komponen
ContextMenuStrip.
b. Buat menu item Cut, Copy, Paste, dan Select All pada
ContextMenuStrip. Atur propert-properti Name dari menu popup, misal popCut,
popCopy, popPaste, dan popAll.
c. Untuk mengaitkan menu popup dengan kontrol, tetapkan nilai
properti ContextMenuStrip di RichTextBox.
d. Lengkapi kode programnya.
Syntax:
Public Class
Form1
Private Sub
mnuCut_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuCut.Click
If Me.RichTextBox1.SelectedText
<> "" Then
Me.RichTextBox1.Cut()
End If
End Sub
Private Sub
mnuCopy_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuCopy.Click
If Me.RichTextBox1.SelectedText
<> "" Then
Me.RichTextBox1.Copy()
End If
End Sub
Private Sub
mnuPaste_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuPaste.Click
Me.RichTextBox1.Paste()
End Sub
Private Sub
mnuAll_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuAll.Click
Me.RichTextBox1.SelectAll()
End Sub
Private Sub
popCut_Click_1(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
popCut.Click
If Me.RichTextBox1.SelectedText
<> "" Then
Me.RichTextBox1.Cut()
End If
End Sub
Private Sub
popCopy_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
popCopy.Click
If Me.RichTextBox1.SelectedText
<> "" Then
Me.RichTextBox1.Copy()
End If
End Sub
Private Sub
popPaste_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
popPaste.Click
Me.RichTextBox1.Paste()
End Sub
Private Sub
popAll_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
popAll.Click
Me.RichTextBox1.SelectAll()
End Sub
End Class
Keluaran Program seperti dibawah ini:
Tidak ada komentar:
Posting Komentar