Results 1 to 3 of 3

Thread: Button Alignment

  1. #1

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Button Alignment

    VB Code:
    1. 'Place a command button(Command1) And a check box(Check1) on the form
    2. 'Click checkbox to set the alignment
    3.  
    4. 'Alignment constants
    5. Private Const BS_CENTER& = &H300&
    6. Private Const BS_LEFT& = &H100&
    7. Private Const BS_RIGHT& = &H200&
    8. Private Const BS_TOP& = &H400&
    9. Private Const GWL_STYLE& = (-16)
    10. 'API Calls
    11. Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
    12. Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    13.  
    14. Private Sub Check1_Click()
    15.     'Declare Variables
    16.     Dim tmpValue&
    17.     Dim Align&
    18.     Dim ret&
    19.     Dim fAlignment As Long
    20.    
    21.     'Check if the state is checked
    22.     If Check1.Value = Checked Then 'Yes
    23.         fAlignment& = BS_LEFT
    24.         tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT
    25.         ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
    26.         Command1.Refresh
    27.     Else 'No
    28.         fAlignment& = BS_CENTER
    29.         tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT Or BS_LEFT
    30.         ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
    31.         Command1.Refresh
    32.     End If
    33. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Dont mean to give you a hard time but actually credit should go
    to Merrion. I can see that you got the code from our posts in this
    thread and made the code bank deposit right after we posted our
    posts.
    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

  3. #3

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    no Rob. i don't got the code from ur posts. i have that code in my code library from a very long period.

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