locked
simply disable textbox context menu RRS feed

  • Question

  • ok.. i've read where you can disable the default context menu for a textbox.  But what I neeed to do.. is remove the default and add my own context menu items... Thus far, i've not foudn a way yet

    any sugguestions?

    Friday, December 24, 2010 6:11 AM

Answers

  • here is a simple example. try it in an app with just a TextBox

    I'll leave the rest up to you :)

     Dim myCMS As New ContextMenuStrip
     WithEvents cmsiColor As New ToolStripMenuItem
     WithEvents cmsiFont As New ToolStripMenuItem
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      cmsiColor.Text = "Color"
      cmsiFont.Text = "Font"
    
      myCMS.Items.Add(cmsiColor)
      myCMS.Items.Add(cmsiFont)
    
      TextBox1.ContextMenuStrip = myCMS
    
      TextBox1.Text = "hello world"
     End Sub
    
     Private Sub cmsiColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmsiColor.Click
      Dim cbd As New ColorDialog
      If cbd.ShowDialog = DialogResult.OK Then
       TextBox1.ForeColor = cbd.Color
      End If
     End Sub
    
     Private Sub cmsiFont_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmsiFont.Click
      Dim fbd As New FontDialog
      If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
       TextBox1.Font = fbd.Font
      End If
     End Sub
    
    • Marked as answer by LandLord323 Saturday, December 25, 2010 6:20 PM
    Friday, December 24, 2010 6:35 AM
  • you can set the TextBox's ContextMenuStrip to your own blank one.

    Dim mycms As New ContextMenuStrip
        TextBox1.ContextMenuStrip = mycms
    
    • Marked as answer by LandLord323 Monday, December 27, 2010 5:07 PM
    Sunday, December 26, 2010 8:23 PM

All replies

  • here is a simple example. try it in an app with just a TextBox

    I'll leave the rest up to you :)

     Dim myCMS As New ContextMenuStrip
     WithEvents cmsiColor As New ToolStripMenuItem
     WithEvents cmsiFont As New ToolStripMenuItem
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      cmsiColor.Text = "Color"
      cmsiFont.Text = "Font"
    
      myCMS.Items.Add(cmsiColor)
      myCMS.Items.Add(cmsiFont)
    
      TextBox1.ContextMenuStrip = myCMS
    
      TextBox1.Text = "hello world"
     End Sub
    
     Private Sub cmsiColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmsiColor.Click
      Dim cbd As New ColorDialog
      If cbd.ShowDialog = DialogResult.OK Then
       TextBox1.ForeColor = cbd.Color
      End If
     End Sub
    
     Private Sub cmsiFont_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmsiFont.Click
      Dim fbd As New FontDialog
      If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
       TextBox1.Font = fbd.Font
      End If
     End Sub
    
    • Marked as answer by LandLord323 Saturday, December 25, 2010 6:20 PM
    Friday, December 24, 2010 6:35 AM
  • aww... some things are complicated by their own simplicity....

    Thanks

    Saturday, December 25, 2010 6:20 PM
  • ok.. what the answer for not letting any default context menu come up???

    Sunday, December 26, 2010 8:14 PM
  • you can set the TextBox's ContextMenuStrip to your own blank one.

    Dim mycms As New ContextMenuStrip
        TextBox1.ContextMenuStrip = mycms
    
    • Marked as answer by LandLord323 Monday, December 27, 2010 5:07 PM
    Sunday, December 26, 2010 8:23 PM
  • ok, good work around.  and it will work for what I am doing.

    I used the

    Private Declare Function LockWindowUpdate Lib "user32"

     

     

    (ByVal hwndLock As Long) As Long

    in vb 6

    Monday, December 27, 2010 5:07 PM