none
context menu will not proceed with command when it loses focus.. RRS feed

  • Question

  • i have a checkbox, when checked, contextmenu shows and remains visible until unchecked..  then i ran into a problem.. if i click any other control on my form, the context menu disappears and the checkbox remains checked.  i have tried placing

    checkbox1.Checked = False
    into the ContextMenuStrip1_LostFocus, and if that would have worked, i would not be posting this question..

    any idea on how to go about this, other than the only option i can think of, and that is to add a line of code to ALLLLLLLLLLLLLLLLLLLL  my controls to uncheck the checkbox if clicked.. 

    thanx in advance...
    trujade
    Wednesday, June 3, 2009 12:50 AM

Answers

  • This code works better:

        Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked = True Then
                ContextMenuStrip1.AutoClose = False
                ContextMenuStrip1.Visible = True
            ElseIf CheckBox1.Checked = False Then
                ContextMenuStrip1.AutoClose = True
                ContextMenuStrip1.Visible = False
            End If
        End Sub
    
    
    Wednesday, June 3, 2009 1:11 AM

All replies

  • Add the following line to your FORM LOAD SUB (replace the CONTEXTMENUSTRIP1 part with the name of your CONTEXT MENU STRIP).

    ContextMenuStrip1.AutoClose = False
    • Edited by Earl Tut Wednesday, June 3, 2009 1:08 AM
    Wednesday, June 3, 2009 1:06 AM
  • This code works better:

        Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked = True Then
                ContextMenuStrip1.AutoClose = False
                ContextMenuStrip1.Visible = True
            ElseIf CheckBox1.Checked = False Then
                ContextMenuStrip1.AutoClose = True
                ContextMenuStrip1.Visible = False
            End If
        End Sub
    
    
    Wednesday, June 3, 2009 1:11 AM
  • that's a tongue twister..   took me a second to understand it..
    thanx Junner2003..

    trujade
    • Edited by •.trujade.• Wednesday, June 3, 2009 1:15 AM missed the reply by a sec, so i changed my reply
    Wednesday, June 3, 2009 1:12 AM
  • My 2nd reply takes care of it. However, you still can add / replace the following line

    ContextMenuStrip1.Visible = False

     

    with

    ContextMenuStrip1.Close()
    Wednesday, June 3, 2009 1:22 AM
  • thanx.
    trujade
    Wednesday, June 3, 2009 1:24 AM