I just couldn't let this go without trying to come up with something. Here is a sample that puts the dialog caption in the center of the dialog and keeps it centered if the dialog is resized. You might have to tweak the first five variables. On my XP computer
Let>vPixelsInASpace=3 works good. On my Windows 7 computer I have
Let>vPixelsInASpace=3.4. For some reason using a modal dialog fails.
Main caveat is that the caption can't exceed 254 characters so if the dialog gets too wide it will lose its center. But it is just a visual affect anyway so unless you get a ruler out and measure the screen you might not even notice.
Code: Select all
Let>vFont=Arial
Let>vSize=12
Let>vStyle=1
Let>vColor=0
Let>vPixelsInASpace=3
Dialog>TextSizeCatureDialog
object TextSizeCatureDialog: TForm
AutoSize = True
AlphaBlend = True
AlphaBlendValue = 0
BorderStyle = bsNone
object Label1: TLabel
Left = 0
Top = 0
end
end
EndDialog>TextSizeCatureDialog
Dialog>Dialog1
object Dialog1: TForm
Left = 490
Top = 205
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'A Caption to be Centered in the Dialog'
ClientHeight = 223
ClientWidth = 484
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnResize,ReCenterCaption
AddDialogHandler>Dialog1,,OnClose,Quit
GoSub>ReCenterCaption
Show>dialog1
//Show>dialog1,res1
Label>Loop
Wait>0.01
Goto>Loop
SRT>ReCenterCaption
GetDialogProperty>Dialog1,,ClientWidth,vDiaWide
GetDialogProperty>Dialog1,,Caption,vDiaCap
Trim>vDiaCap,vDiaCap
Let>vText=vDiaCap
SetDialogProperty>TextSizeCatureDialog,label1,Caption,vText
SetDialogObjectFont>TextSizeCatureDialog,label1,vFont,vSize,vStyle,vColor
Let>WIN_USEHANDLE=1
Show>TextSizeCatureDialog
GetWindowSize>TextSizeCatureDialog.handle,TextSizeX,TextSizeY
Let>WIN_USEHANDLE=0
Let>SpaceLength={round((%vDiaWide%/2)-(%TextSizeX%/2))}
Let>CaptionKK=0
Repeat>CaptionKK
Add>Captionkk,1
Let>vDiaCap=%space%%vDiaCap%
Length>vDiaCap,caplen
//Apparently a caption is limited to 254 characters.
If>caplen>253
Let>captionkk=99999999999
EndIf
Until>CaptionKK>{%SpaceLength%/%vPixelsInASpace%}
Length>vDiaCap,caplen
SetDialogProperty>Dialog1,,Caption,vDiaCap
END>ReCenterCaption
SRT>Quit
Exit>0
END>Quit