How to disable text box

vb6 India
  • 16 years ago

    How to disable popup menu from textbox

  • 16 years ago

    There are two ways to do this. Either subclass the WM_INITMENUPOPUP  message and consume it, or use the following instructions (from MSDN):


    Start a new Standard EXE project in Visual Basic. Form1 is created by default.



    Add a TextBox control to Form1.



    Choose Menu Editor from the Tools menu and create a menu named mnuPopUp on Form1. Deselect the Visible CheckBox and add items such as the following:



        File
           New
           Open





    Add the following code to the code window of Form1:



         Private Declare Function LockWindowUpdate Lib "user32" _
            (ByVal hwndLock As Long) As Long


         Private Sub mnuOne_Click()
            Text1.Text = "Menu One was clicked"
         End Sub


         Private Sub mnuTwo_Click()
            Text1.Text = "Menu two was clicked"
         End Sub


         Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, _
            X As Single, Y As Single)


            If Button = vbRightButton Then
            ' Avoid the 'disabled' gray text by locking updates
               LockWindowUpdate Text1.hWnd


               ' A disabled TextBox will not display a context menu
               Text1.Enabled = False


               ' Give the previous line time to complete
               DoEvents


               ' Display our own context menu
               PopupMenu mnuPopup


               ' Enable the control again
               Text1.Enabled = True


               ' Unlock updates
               LockWindowUpdate 0&
            End If
         End Sub





    Save and run the project.



    Alternate-mouse click on Text1. Only the custom menu is displayed. The standard editing menu is not shown.

  • 16 years ago

    There is a sample "WinUI" in this VB source code control:


    http://www.banasoft.com/DownLoad/BNHkLib.exe

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold