Das kannst du über das StringFormat einstellen. Um den Text horizontal kannst du _GDIPlus_StringFormatSetAlign benutzen. Für die vertikale Ausrichtung braucht man allerdings eine Funktion namens _GDIPlus_StringFormatSetLineAlign aus der GDIP.au3 (nicht in den Standard-Includes). In der GDIP.au3 gibt es übrigens noch mehr solcher nützlicher Funktionen, kannst du dir ja mal anschauen (einfach per google suchen). Ich hab mal das Beispiel aus der Hilfe modifiziert damit es den Text vertikal sowie horizontal zentriert.
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Local $hWnd = GUICreate("GDI+ Example", 400, 300)
GUISetState()
_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsClear($hGraphics)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF009900)
Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
Local $hFont = _GDIPlus_FontCreate($hFamily, 36)
Local $hLayout = _GDIPlus_RectFCreate(0, 0, 400, 300)
Local $hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)
_GDIPlus_StringFormatSetLineAlign($hStringFormat, 1)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush)
Do
Local $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_StringFormatSetLineAlign
; Description ...: Sets the line alignment of a StringFormat object in relation to the origin of a layout rectangle
; Syntax.........: _GDIPlus_StringFormatSetLineAlign($hStringFormat, $iStringAlign)
; Parameters ....: $hStringFormat - Pointer to a StringFormat object
; $iStringAlign - Type of line alignment to use:
; |0 - Alignment is towards the origin of the bounding rectangle
; |1 - Alignment is centered between origin and the height of the formatting rectangle
; |2 - Alignment is to the far extent (right side) of the formatting rectangle
; Return values .: Success - True
; Failure - False and either:
; |@error and @extended are set if DllCall failed
; |$GDIP_STATUS contains a non zero value specifying the error code
; Remarks .......: The line alignment setting specifies how to align the string vertically in the layout rectangle.
; The layout rectangle is used to position the displayed string
; Related .......: _GDIPlus_StringFormatGetLineAlign
; Link ..........; @@MsdnLink@@ GdipSetStringFormatLineAlign
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_StringFormatSetLineAlign($hStringFormat, $iStringAlign)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetStringFormatLineAlign", "hwnd", $hStringFormat, "int", $iStringAlign)
If @error Then Return SetError(@error, @extended, False)
$GDIP_STATUS = $aResult[0]
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_StringFormatSetLineAlign