Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.170
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18363.0
This follows on from a Wish List post that I had for a way to left & right align two text strings in the title bar. This solution does what I want and while not perfect is possibly something that may be useful for others.
You need to be able to capture the inuse area and then work out how many spaces to insert between the two strings. I have been able to get most of this but need to allow for a 10% margin for widths that I have not been able to get (borders,icon)
Running the below code returns this..
$Product = 'cnwiniadmin'
$script:version = '1.0.0.0'
#Determine width of titlebar caption buttons
$def = @"
public enum SystemMetric
{
SM_CXSIZE = 0x0030, // 0x0030
}
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(SystemMetric smIndex);
"@
Add-Type -Namespace NativeMethods -Name User32Dll -MemberDefinition $def
$CaptionButtonSize = [NativeMethods.User32Dll]::GetSystemMetrics([NativeMethods.User32Dll+SystemMetric]::SM_CXSIZE)
$Font = [System.Drawing.SystemFonts]::CaptionFont
$TotalWidth = ($MainForm.clientsize).width
$Gfx = $MainForm.CreateGraphics()
$NoPadding = [System.Windows.Forms.TextFormatFlags]::NoPadding
$Space = ' '
$CompanyText = '© ' + (Get-Date -Format 'yyyy') + ' Jade Software Corporation'
$ProductText = $Product + ' v' + $script:version
$SpaceSize = ([System.Windows.Forms.TextRenderer]::MeasureText($Gfx, $Space, $font, $MainForm.clientsize, $NoPadding)).width
$InuseArea = ($CaptionButtonSize * 3)
$InuseArea += ([System.Windows.Forms.TextRenderer]::MeasureText($Gfx, $ProductText, $font, $MainForm.clientsize, $NoPadding)).width
$InuseArea += ([System.Windows.Forms.TextRenderer]::MeasureText($Gfx, $CompanyText, $font, $MainForm.clientsize, $NoPadding)).width
$InuseArea += $SpaceSize
$InuseAreaWithPadding = $InuseArea
#Determine space padding
$i=0
do
{
$i++
$InuseAreaWithPadding += $SpaceSize
}
# Allow for padding so stop once we reach 90%
until ($InuseAreaWithPadding -ge ($TotalWidth*0.9) )
$MainForm.text = $ProductText + ' ' * $i + $CompanyText
Formatting the TitleBar text area
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.