Align Text on a Command Button

Align Text on a Command Button

If you’ve ever wanted to align text on a command button and found you can do it only by using spaces in the caption, there are a couple of constants that can help you do this with the SetWindowLong API Call. Add this code to a standard BAS module, then call it at will, passing the command button and the desired combination of vertical and horizontal alignment values:

 Option ExplicitPrivate Declare Function GetWindowLong Lib _	"user32" Alias "GetWindowLongA" (ByVal hWnd _	As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib _	"user32" Alias "SetWindowLongA" (ByVal hWnd _	As Long, ByVal nIndex As Long, ByVal _	dwNewLong As Long) As LongPrivate Const BS_LEFT As Long = &H100Private Const BS_RIGHT As Long = &H200Private Const BS_CENTER As Long = &H300Private Const BS_TOP As Long = &H400Private Const BS_BOTTOM As Long = &H800Private Const BS_VCENTER As Long = &HC00Private Const BS_ALLSTYLES = BS_LEFT Or BS_RIGHT _	Or BS_CENTER Or BS_TOP Or BS_BOTTOM Or _	BS_VCENTERPrivate Const GWL_STYLE& = (-16)Public Enum bsHorizontalAlignments	bsLeft = BS_LEFT	bsRight = BS_RIGHT	bsCenter = BS_CENTEREnd EnumPublic Enum bsVerticalAlignments	bsTop = BS_TOP	bsBottom = BS_BOTTOM	bsVCenter = BS_VCENTEREnd EnumPublic Sub AlignButtonText(cmd As CommandButton, _	Optional ByVal HStyle As _	bsHorizontalAlignments = bsCenter, _	Optional ByVal VStyle As _	bsVerticalAlignments = bsVCenter)	Dim oldStyle As Long	' get current style	oldStyle = GetWindowLong(cmd.hWnd, GWL_STYLE)	' clear existing alignment setting(s)	oldStyle = oldStyle And (Not BS_ALLSTYLES)	' set new style and refresh button	Call SetWindowLong(cmd.hWnd, GWL_STYLE, _		oldStyle Or HStyle Or VStyle)	cmd.RefreshEnd Sub
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes