Global $dpi
$dpi = CDbl(ReadValue("HKCU\Control Panel\Desktop\WindowMetrics","AppliedDPI"))
;region ScriptForm Designer
;region Constructor
Break On
$System = CreateObject("KiXtart.System")
;endregion
;region Post-Constructor Custom Code
Dim $Ret
$Ret = SetOption("Explicit", "on")
Dim $
;endregion
;region Form Creation
;Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
;When working with the ScriptForm designer this region and any changes within may be overwritten.
;~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $Form1
$Form1 = $System.Form()
$Form1.Text = "Just a simple test"
;~~< TextBox1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $TextBox1
$TextBox1 = $Form1.Controls.TextBox()
$TextBox1.Size = 183, 20
$TextBox1.Location = 89, 93
;~~< Label1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $Label1
$Label1 = $Form1.Controls.Label()
$Label1.Text = "My Box:"
$Label1.Size = 70, 23
$Label1.Location = 13, 96
;~~< Button1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $Button1
$Button1 = $Form1.Controls.Button()
$Button1.Text = "Resize"
$Button1.Size = 75, 23
$Button1.Location = 61, 184
$Button1.OnClick = "Resize( $$Button1 )"
;~~< Label2 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global $Label2
$Label2 = $Form1.Controls.Label()
$Label2.Text = "Enter some text and press "+Chr(34)+"Resize"+Chr(34)+" to resize the width of the textbox"
$Label2.Size = 259, 46
$Label2.Location = 13, 24
;endregion
;region Custom Code
$TextBox1.text = "123.25GB"
;endregion
;region Event Loop
$Form1.Show
While $Form1.Visible
$=Execute($System.Application.DoEvents)
Loop
;endregion
;endregion
;region Event Handlers
Function Resize( $object )
$TextBox1.width = DPIAdjust(PixelStrSize($TextBox1.text))
$TextBox1.SelectionStart = 0
$TextBox1.SelectionLength = 0
EndFunction
Function PixelStrSize($sInput)
Dim $, $i, $c
$ = SetOption("CaseSensitivity", "On")
For $i = 1 to Len($sInput)
$c = SubStr($sInput, $i, 1)
Select
Case $c = "'"
$PixelStrSize = CDbl($PixelStrSize) + 2
Case InStr('fjt !,.:;-/\()"Jr', $c)
$PixelStrSize = CDbl($PixelStrSize) + 3
Case InStr("szkvxy?cL", $c)
$PixelStrSize = CDbl($PixelStrSize) + 5
Case InStr("ughdeK0123456789$BEFYZabnopqP", $c)
$PixelStrSize = CDbl($PixelStrSize) + 6
Case InStr("UVRSTNACDGH*+X<=>&#OQ", $c)
$PixelStrSize = CDbl($PixelStrSize) + 8
Case InStr("Mwm", $c)
$PixelStrSize = CDbl($PixelStrSize) + 9
Case InStr("@%W", $c)
$PixelStrSize = CDbl($PixelStrSize) + 12
Case 1
$PixelStrSize = CDbl($PixelStrSize) + 10
EndSelect
Next
$PixelStrSize = $PixelStrSize + 10
$ = SetOption("CaseSensitivity", $)
EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETS SIZES DYNAMICALLY ACCORDING TO DPI. ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function DPIAdjust($n)
If Len($dpi)=0
$dpi = CDbl(96)
Endif
$DPIAdjust = ($dpi/96.000)*$n
EndFunction