none
ToolStripDropDownButton stays selected after using colordialog RRS feed

  • Question

  • I am using a ToolStripDropDownButton (defined as Tsdd_SelColour in this code to select a colordialog (defined as dlg_Colour in this code).  After closing dlg_Colour, the Tsdd_SelColour button remains highlighted, as if the mouse is hovering on the control.  If I move the mouse into any other button on the toolstrip, the highlight goes off.  This is the basic code I use:

    Private Sub Tsdd_SelColour_Click(sender As Object,
    			         e As EventArgs) _
    				 Handles Tsdd_SelColour.Click
    
    	Dim Result As DialogResult
    
    	Result = dlg_Colour.ShowDialog()
    
    	If Result = DialogResult.OK Then
    		' Do things
    	End If
    
    	Tsdd_SelColour.BackColor = Color.White
    
    End Sub
    

    I inserted the line Tsdd_SelColour.BackColor = Color.White in an attempt to clear the button selection but it does not work.  Any suggestions as to how I could "unselect" the ToolStripDropDownButton?

    P.S. As an aside, is there a colour dialog that opens up a colour selection like the one in Word or Excel?

    HotIndigo.

    Friday, February 28, 2020 8:54 AM

Answers

  • Hi tommytwotrain,

    Tsdd_SelColour is my name for the toolstripdropdownmenu.  I don't know if this is significant but the control does not have an image associated with it.  The colordialog opens when the control is clicked.

       I have not come across ShowColorDialogToolStripMenuItem before.

    HotIndigo

    Are we talking about the same thing?

    Seems to me you are missing how the ToolStripDropDownButton control works?

    You click the button arrow, then you click to select from the menu list that drops down.

    The button click fires the button click event for the control and the Tool​Strip​Item.click event fires the drop down menu/list item click event. In the menu item click you show the dialog. Not the button click.

    Did you define a menu? Lets see an image.

    To make the menu click event, in the form designer view, double click the menu name as shown below. An event sub routine is created with the menu name as in my example above. Try it.

    :)

     


    • Marked as answer by HotIndigo Sunday, March 1, 2020 7:11 PM
    Saturday, February 29, 2020 12:43 PM

All replies

  • Use ActiveControl = SomeControl e.g. so if you want a RichTextBox to be active use ActiveControl = RichTextBox1

    Private Sub Tsdd_SelColour_Click(sender As Object,
    			         e As EventArgs) _
    				 Handles Tsdd_SelColour.Click
    
    	Dim Result As DialogResult
    
    	Result = dlg_Colour.ShowDialog()
    
    	If Result = DialogResult.OK Then
    		ActiveControl =RichTextBox1
    	End If
    
    	Tsdd_SelColour.BackColor = Color.White
    
    End Sub
    
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange



    Friday, February 28, 2020 10:24 AM
    Moderator
  • Hi Karen,

       Tried it with some of my controls and even included a rich text box but no change to the behaviour.  Any other suggestions?

    Saturday, February 29, 2020 7:06 AM
  • Hi Karen,

       Tried it with some of my controls and even included a rich text box but no change to the behaviour.  Any other suggestions?

    I cant reproduce the problem.

    My drop down mouse hoover button highlight goes away as soon as I click the drop down button. You must have something else involved?

    Take out the color dialog part and see what happens?

     
    "P.S. As an aside, is there a colour dialog that opens up a colour selection like the one in Word or Excel?"

    Show an image of what you want.

     

    "Any suggestions as to how I could "unselect" the ToolStripDropDownButton?:

    Maybe use a MouseLeave or MouseEnter or VisibleChanged etc ?? event to .refresh the control. Or Me.Focus() (ie Karen's suggestion).

    First make a new form with a reproducible example. You will most likely find your cause trying to make a simple example.

     

     

     

    Public Class Form2
        Private Sub ShowColorDialogToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowColorDialogToolStripMenuItem.Click
            Dim Result As DialogResult
            Dim dlg_Colour As New ColorDialog
    
            Result = dlg_Colour.ShowDialog()
    
            If Result = DialogResult.OK Then
    
    
            End If
    
        End Sub
    End Class



    Saturday, February 29, 2020 8:16 AM
  • I am using a ToolStripDropDownButton (defined as Tsdd_SelColour in this code to select a colordialog (defined as dlg_Colour in this code).  After closing dlg_Colour, the Tsdd_SelColour button remains highlighted, as if the mouse is hovering on the control.  If I move the mouse into any other button on the toolstrip, the highlight goes off.  This is the basic code I use:

    Private Sub Tsdd_SelColour_Click(sender As Object,
    			         e As EventArgs) _
    				 Handles Tsdd_SelColour.Click
    
    	Dim Result As DialogResult
    
    	Result = dlg_Colour.ShowDialog()
    
    	If Result = DialogResult.OK Then
    		' Do things
    	End If
    
    	Tsdd_SelColour.BackColor = Color.White
    
    End Sub

    I inserted the line Tsdd_SelColour.BackColor = Color.White in an attempt to clear the button selection but it does not work.  Any suggestions as to how I could "unselect" the ToolStripDropDownButton?

    P.S. As an aside, is there a colour dialog that opens up a colour selection like the one in Word or Excel?

    HotIndigo.

    Wait, what is:

           Handles Tsdd_SelColour.Click

    is that the menu select or the button? Should be menu as my example?

    PS Yes that is the problem should be menu.click event as the example shows. Here is the problem highlight after using ToolStripDropDownButton1.Click:



    Public Class Form2
    
        'this is the correct event
        Private Sub ShowColorDialogToolStripMenuItem_Click(sender As Object,
              e As EventArgs) Handles ShowColorDialogToolStripMenuItem.Click
    
            Dim Result As DialogResult
            Dim dlg_Colour As New ColorDialog
    
            Result = dlg_Colour.ShowDialog()
    
            If Result = DialogResult.OK Then
    
    
            End If
    
        End Sub
    
    
        'this is the wrong event
        'Private Sub ToolStripDropDownButton1_Click(sender As Object,
        '      e As EventArgs) Handles ToolStripDropDownButton1.Click()
    
        '    Dim Result As DialogResult
        '    Dim dlg_Colour As New ColorDialog
    
        '    Result = dlg_Colour.ShowDialog()
    
        '    If Result = DialogResult.OK Then
    
    
        '    End If
        'End Sub
    End Class

    Saturday, February 29, 2020 8:30 AM
  • Hi tommytwotrain,

    Tsdd_SelColour is my name for the toolstripdropdownmenu.  I don't know if this is significant but the control does not have an image associated with it.  The colordialog opens when the control is clicked.

       I have not come across ShowColorDialogToolStripMenuItem before.

    HotIndigo

    Saturday, February 29, 2020 11:50 AM
  • Hi tommytwotrain,

    Tsdd_SelColour is my name for the toolstripdropdownmenu.  I don't know if this is significant but the control does not have an image associated with it.  The colordialog opens when the control is clicked.

       I have not come across ShowColorDialogToolStripMenuItem before.

    HotIndigo

    Are we talking about the same thing?

    Seems to me you are missing how the ToolStripDropDownButton control works?

    You click the button arrow, then you click to select from the menu list that drops down.

    The button click fires the button click event for the control and the Tool​Strip​Item.click event fires the drop down menu/list item click event. In the menu item click you show the dialog. Not the button click.

    Did you define a menu? Lets see an image.

    To make the menu click event, in the form designer view, double click the menu name as shown below. An event sub routine is created with the menu name as in my example above. Try it.

    :)

     


    • Marked as answer by HotIndigo Sunday, March 1, 2020 7:11 PM
    Saturday, February 29, 2020 12:43 PM
  • Hi tommytwotrain,

       Thank you for your comments - you have clarified issues for me and I have now solved the problem.  Many thanks.

    HotIndigo.

    Sunday, March 1, 2020 7:11 PM