Toolbar DropDownButton doesnt show dropdown if you click on the botton?
If you have a DropDownButton in your toolbar it seems like it only shows the drop down menu when you click on the little down arrow next to the button (which is somewhat natural:D)
I'm trying to make a button that would show the drop down whether you click on the button or the dropdown arrow next to it. But I cant seem to find a way to find the location of a toolbar button (and hence I have no idea where to put my dropdown context menu)
any ideas? I guess I have to figure out the location of the button within the toolbar but I dunno how
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Why don't you try with:
VB Code:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
If e.Button Is ToolBarButton1 Then
ContextMenu1.Show(control, position)
End If
End Sub
HTH!
Nebo
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
yeah but as I said I dont know how to determine the position of the button within the toolbar:( that's the main problem
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Here's the solution ;)
VB Code:
Dim pos As Point
pos = ToolBar1.MousePosition
If e.Button Is ToolBarButton1 Then
ContextMenu1.Show(ToolBar1, ToolBar1.PointToClient(pos))
End If
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Hi,
The way I do it is to assume that the button is of standard width (becaue most of my buttons are) and subdivide the toolbar into several pieces by the unusually shaped buttons (dropdowns, separators etc). I then check the rectangle.X property to determine which separators I am between at the present time and use it to display a description in the status bar:
VB Code:
Dim mousex As Integer = e.X
If mousex < tools.Buttons(1).Rectangle.X Then
statusbar.Panels(0).Text = "Some description"
ElseIf mousex > (tools.Buttons(1).Rectangle.X + tools.Buttons(1).Rectangle.Width) And mousex < tools.Buttons(6).Rectangle.X Then
statusbar.Panels(0).Text = tools.Buttons(Int((mousex - (tools.Buttons(1).Rectangle.X + tools.Buttons(1).Rectangle.Width)) / tools.Buttons(0).Rectangle.Width) + 2).description
ElseIf mousex > (tools.Buttons(6).Rectangle.X + tools.Buttons(6).Rectangle.Width) And mousex < tools.Buttons(12).Rectangle.X Then
statusbar.Panels(0).Text = tools.Buttons(Int((mousex - (tools.Buttons(6).Rectangle.X + tools.Buttons(6).Rectangle.Width)) / tools.Buttons(0).Rectangle.Width) + 7).description
ElseIf
'blahblahblah
Else
statusbar.Panels(0).Text = ""
End If
End If
Here I have a separator as buttons(1), buttons(6), buttons(12) etc. Basically, it says:
If mouse X > separator 1 and mouse X < separator 2 Then
Get the difference between mouse X and the right hand edge of the separator
Divide this by the standard button width to give a number between 0 and the number of buttons in this part of the toolbar
Add on the offset because the separator is at position 6 etc.
Stick the description in the statusbar.
You could do similar, but display the context menu only if you're over the correct button.
HTH
zaza
EDIT: Hey, I like that PointToClient thing. Looks handy.
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Huh, looks complicated....
I like PointToClient too :)
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
thanks zaza, I'll stick to the simple method:D:D
thanks nebo_vb too :) Control.MousePosition property is somewhat useful but doesnt make much sense. It's working fine now :)
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Here is how it would do it.
VB Code:
Private Sub tbbNavigation_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbbNavigation.ButtonClick
Select Case Me.tbbNavigation.Buttons.IndexOf(e.Button)
Case 1
'Back
Me.ContextMenu1.Show(Me.tbbNavigation, New Point(e.Button.Rectangle.Left, e.Button.Rectangle.Bottom))
Case 2
'Next
Case 3
'Home
Case 4
'Search
End Select
End Sub
:D
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
oh w00t
button.Rectangle gives the location:D didnt think of that:D:D thanks
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Quote:
button.Rectangle gives the location
Er...that was my "complicated" method too :D
Although I trap mine in the mousemove event so I can't use the e.button.
Nice code though, RD.
zaza
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Thanks zaza. I think I am making the transition from VB6 to VB.NET allot better now after, what, 6 months. :(
Still, I have a long way to go.
Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?
Quote:
Originally Posted by zaza
Er...that was my "complicated" method too :D
Although I trap mine in the mousemove event so I can't use the e.button.
Nice code though, RD.
zaza
sorry :bigyello: I read the first few lines and I thought that you're assuming a fixed width for each button so I didnt look at the code
thaks to all anyways :afrog: