Results 1 to 13 of 13

Thread: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Resolved 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)

    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
    Last edited by MrPolite; Jun 11th, 2005 at 09:22 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    Why don't you try with:

    VB Code:
    1. Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
    2.         If e.Button Is ToolBarButton1 Then
    3.             ContextMenu1.Show(control, position)
    4.         End If
    5.     End Sub

    HTH!

    Nebo
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    Here's the solution

    VB Code:
    1. Dim pos As Point
    2.         pos = ToolBar1.MousePosition
    3.         If e.Button Is ToolBarButton1 Then
    4.             ContextMenu1.Show(ToolBar1, ToolBar1.PointToClient(pos))
    5.         End If
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    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:
    1. Dim mousex As Integer = e.X
    2.  
    3.         If mousex < tools.Buttons(1).Rectangle.X Then
    4.            statusbar.Panels(0).Text = "Some description"
    5.         ElseIf mousex > (tools.Buttons(1).Rectangle.X + tools.Buttons(1).Rectangle.Width) And mousex < tools.Buttons(6).Rectangle.X Then
    6.              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
    7.         ElseIf mousex > (tools.Buttons(6).Rectangle.X + tools.Buttons(6).Rectangle.Width) And mousex < tools.Buttons(12).Rectangle.X Then
    8.              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
    9.         ElseIf
    10.  
    11.           'blahblahblah
    12.         Else
    13.                 statusbar.Panels(0).Text = ""
    14.             End If
    15.        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.
    Last edited by zaza; Jun 11th, 2005 at 04:45 PM.

  6. #6
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    Huh, looks complicated....

    I like PointToClient too
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    thanks zaza, I'll stick to the simple method
    thanks nebo_vb too Control.MousePosition property is somewhat useful but doesnt make much sense. It's working fine now
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    Here is how it would do it.
    VB Code:
    1. Private Sub tbbNavigation_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbbNavigation.ButtonClick
    2.     Select Case Me.tbbNavigation.Buttons.IndexOf(e.Button)
    3.         Case 1
    4.             'Back
    5.             Me.ContextMenu1.Show(Me.tbbNavigation, New Point(e.Button.Rectangle.Left, e.Button.Rectangle.Bottom))
    6.         Case 2
    7.             'Next
    8.         Case 3
    9.             'Home
    10.         Case 4
    11.             'Search
    12.     End Select
    13. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    oh w00t
    button.Rectangle gives the location didnt think of that thanks
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    ..
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    button.Rectangle gives the location

    Er...that was my "complicated" method too
    Although I trap mine in the mousemove event so I can't use the e.button.

    Nice code though, RD.

    zaza

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Toolbar DropDownButton doesnt show dropdown if you click on the botton?

    Quote Originally Posted by zaza
    Er...that was my "complicated" method too
    Although I trap mine in the mousemove event so I can't use the e.button.

    Nice code though, RD.

    zaza
    sorry 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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width