Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a TextBox control that does not display a context menu in VB .NET
DescriptionMake a TextBox control that does not display a context menu in VB .NET. It overrides the control's WndProc subroutine and ignores WM_CONTEXTMENU messages.
KeywordsTextBox, context menu, popup menu
CategoriesVB.NET, Controls
 
The NoCtxMnuTextBox class inherits from TextBox. It overrides the TextBox's WndProc and ignores any WM_CONTEXTMENU messages that it sees. It passes all other messages on to the parent's version of WndProc for processing.
 
Public Class NoCtxMnuTextBox
    Inherits System.Windows.Forms.TextBox
    ...
    Protected Overrides Sub WndProc(ByRef m As _
        System.Windows.Forms.Message)
        Const WM_CONTEXTMENU As Integer = &H7B
        If m.Msg <> WM_CONTEXTMENU Then
            MyBase.WndProc(m)
        End If
    End Sub
End Class
 
To get this program to work, you need to load and compile it. Then right-click on the Toolbox and select Add/Remove Items. Click Browse, browse to the program's bin directory, and select the executable that you just built. This adds the control to the Toolbox.

Now use the Toolbox to add the control to the form.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated