-
VB.NET context menu help
Hi
I need some help with context menu creation with VB.net . I am trying to create a context menu with CUT ,PASTE & DELETE . I caqn create the menu but it is not functioning ( I can not CUT or Paste or Delete ) Please help . My code is below .
Imports System.IO
Imports System.ContextBoundObject
Imports System.ContextStaticAttribute
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents RichTextBox2 As System.Windows.Forms.RichTextBox
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.RichTextBox2 = New System.Windows.Forms.RichTextBox
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.ContextMenu = Me.ContextMenu1
Me.RichTextBox1.Location = New System.Drawing.Point(328, 120)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1"
'
'RichTextBox2
'
Me.RichTextBox2.ContextMenu = Me.ContextMenu1
Me.RichTextBox2.Location = New System.Drawing.Point(512, 120)
Me.RichTextBox2.Name = "RichTextBox2"
Me.RichTextBox2.TabIndex = 1
Me.RichTextBox2.Text = "RichTextBox2"
'
'ContextMenu1
'
Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3, Me.MenuItem4})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = ""
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.Text = "CUT"
'
'MenuItem3
'
Me.MenuItem3.Index = 2
Me.MenuItem3.Text = "COPY"
'
'MenuItem4
'
Me.MenuItem4.Index = 3
Me.MenuItem4.Text = "PASTE"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(1008, 398)
Me.ContextMenu = Me.ContextMenu1
Me.Controls.Add(Me.RichTextBox2)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox1.Cut()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox1.Copy()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox2.Paste()
End Sub
End Class
-
Your Click event procedures are not "connected" to anything. In order to be called when a MenuItem is clicked, they need a Handles clause:
Private Sub MenuItem1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem1.Click
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
VB.NET context menu
Hi
Thanks so much . The context menu solution you gave has worked
Thanks
Similar Threads
-
Replies: 0
Last Post: 07-27-2005, 07:42 AM
-
Replies: 1
Last Post: 07-05-2005, 04:02 PM
-
By JetserKing in forum VB Classic
Replies: 0
Last Post: 02-15-2005, 02:12 PM
-
Replies: 8
Last Post: 07-02-2002, 02:09 PM
-
By David Quick in forum VB Classic
Replies: 4
Last Post: 04-06-2001, 02:13 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks