Results 1 to 5 of 5

Thread: [RESOLVED] Checkbox on a Toolbar

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Resolved [RESOLVED] Checkbox on a Toolbar

    Hi, recently I created a small application and I put a Checkbox on the Toolbar to shut down the computer after the application is finished.

    Everything looks fine on my computer (XP) and heard nothing from the people who tested the application.




    A few days ago I submitted the application to softpedia.com and they ceated their own screenshots, but the Checkbox is positioned over the last button on the Toolbar.




    Does anybody know how to fix this?
    The Align property is set to 1 - vbAlignTop
    I would like to keep it that way, because if I set it to 0 - vbAlignNone, the toolbar gets an ugly border.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Checkbox on a Toolbar

    Here is how I do it:

    - add standard checkbox to your form
    - assign "placeholder" key to one of your toolbar buttons
    - use code similar to this:
    Code:
    Option Explicit
    
    Private Declare Function SetParent Lib "user32" _
        (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private Sub Form_Load()
        With Toolbar1
            .Buttons("placeholder").Style = tbrPlaceholder
            .Buttons("placeholder").Width = Check1.Width + 120
            Set Check1.Container = Toolbar1
            'SetParent Check1.hWnd, Toolbar1.hWnd
            Check1.Move .Buttons("placeholder").Left + 120, (.Height - Check1.Height) / 2
            Check1.ZOrder
        End With
    End Sub
    NOTE: you can use Container or SetParent - I gave you both options but it's your choice.

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

    Re: Checkbox on a Toolbar

    Another way would be to use an image of a checkbox checked and unchecked and toggle the image upon button click.
    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Checkbox on a Toolbar

    Thank you very much, RhinoBull

    I'm using Container and it works perfectly.

  5. #5

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