versuche einen Richtext in einen EditorGadget vertikal zu zentrieren!
Habe mal im Forum geguckt:
; https://www.purebasic.fr/english/viewto ... 13&t=46519
; http://forums.purebasic.com/english/vie ... 4&start=15
Code: Alles auswählen
#CFM_BACKCOLOR = $4000000
#CFM_EMBOSS = $800
#CFM_OUTLINE = $200
#CFM_SHADOW = $400
#CFM_ANIMATION = $40000
; RichtText$ = "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget"
Global PST_Window
Global PST_EDIT
Global RichtText$
Global LinesNum
Procedure EditorGadgetVCenter(GGadget,ttext.s)
Protected hwndEdit
Protected LineCount
Protected hdc
hwndEdit = GadgetID(GGadget)
LineCount = SendMessage_(hwndEdit,#EM_GETLINECOUNT, 0, 0)
Debug "LineCount = "+LineCount
hdc = GetDC_(hwndEdit)
SelectObject_(hdc,GetGadgetFont(GGadget))
GetTextExtentPoint32_(hdc,ttext,Len(ttext),fsz.SIZE)
ReleaseDC_(hwndEdit,hdc)
;<=== Hier ist der Wurm?
GetClientRect_(hwndEdit,eRect.RECT)
eRect\top = (GadgetHeight(GGadget) - fsz\cy * LineCount) / 2
eRect\bottom = eRect\top + (fsz\cy * LineCount)
If eRect\bottom < GadgetHeight(GGadget)
SendMessage_(hwndEdit,#EM_SETRECT,0,eRect)
EndIf
EndProcedure
Procedure LineFormat(Gadget,FName$,FSize,FColor,BColor,FFlags)
format.CHARFORMAT2
format\cbSize = SizeOf(CHARFORMAT2)
format\dwMask = #CFM_FACE|#CFM_COLOR|#CFM_BACKCOLOR|#CFM_SIZE|#CFM_ITALIC|
#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_EMBOSS|
#CFM_OUTLINE|#CFM_SHADOW|#CFM_LINK|#CFM_SUBSCRIPT|
#CFM_SUPERSCRIPT|#CFM_PROTECTED
;format\dwEffects = #CFE_BOLD|#CFE_ITALIC|#CFE_LINK|#CFE_OUTLINE|#CFE_SHADOW|
; #CFE_STRIKEOUT|#CFE_AUTOBACKCOLOR|#CFE_AUTOCOLOR|
; #CFE_EMBOSS|#CFE_SUBSCRIPT|#CFE_SUPERSCRIPT|#CFE_UNDERLINE
PokeS(@format\szFaceName, FName$)
format\yHeight = FSize*1440/72
format\crTextColor = FColor
format\crBackColor = BColor
format\dwEffects = FFlags
SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure
PST_Window = OpenWindow(#PB_Any,0,0,500,500,"Edit Control VCenter",#WS_SYSMENU | #WS_CAPTION | 1)
PST_EDIT = EditorGadget(#PB_Any,0,0,500,500)
AddGadgetItem(PST_EDIT, 0, "")
LineFormat(PST_EDIT,"Forte",52,$0102FE,$02FEFD,#CFM_UNDERLINE| #CFU_UNDERLINETHICKDASH)
; LineFormat(#Gadget,Font Name,Font Size,Font Color,Font Flags)
RichtText$ = "This is a RED"
AddGadgetItem(PST_EDIT, 1, "This is a RED")
LineFormat(PST_EDIT,"Broadway",24,$73E06D,$02FEFD,#CFM_BOLD)
RichtText$ + "Times new Roman"
AddGadgetItem(PST_EDIT, 2, "Times new Roman")
LineFormat(PST_EDIT,"Times new Roman",16,$FB1404,$C5C5C5,#CFM_ANIMATION)
RichtText$ + "Times new Roman"
AddGadgetItem(PST_EDIT, 3, "This is Italic and Strikeout")
LineFormat(PST_EDIT,"Times new Roman",16,$FB1404,$C5C5C5,#CFM_ANIMATION)
RichtText$ + "This is Italic and Strikeout"
AddGadgetItem(PST_EDIT, 3, "This is Italic and Strikeout")
LineFormat(PST_EDIT,"Times new Roman",16,$FB1404,$C5C5C5,#CFM_ANIMATION)
RichtText$ + "This is Italic and Strikeout"
AddGadgetItem(PST_EDIT, 3, "This is Italic and Strikeout")
RichtText$ + "This is usual Text"
AddGadgetItem(PST_EDIT, 4, "This is usual Text")
;space = (Editor Height - Font Size 1 - Font Size 2 - FontSize .....)/2
space = (200 - 52 - 24 - 16 - 12 - 12)/2
LineFormat(PST_EDIT,"Arial",space,0,0,0)
AddGadgetItem(PST_EDIT, 0, "")
EditorGadgetVCenter(PST_EDIT,RichtText$)
Repeat
EventID = WaitWindowEvent()
Select EventGadget()
EndSelect
Until EventID = #PB_Event_CloseWindow
Jemand mal einen Tip?
Gruss ... Velindos!