StringGadget Vertical?
StringGadget Vertical?
Can you vertically specify with StringGadget?
Thanks
Thanks
Not that I'm aware of. You can certainly draw angled text as demonstrated with:
It is entirely conceivable that you could use code similar to the above in conjunction with, say a subclassed text gadget, in which you take over the paint process and thus get the text gadget to display angled text etc. The problem (at least one of them ) with the string gadget will be the caret.
Your best bet might be to create your own custom control.
Code: Select all
If OpenWindow(0, 0, 0, 640, 400, #PB_Window_SystemMenu, "Angled text!")
hdc = GetDC_(WindowID())
SetBkMode_(hdc, #TRANSPARENT)
hfont = CreateFont_(30,16, 2700,0,0,0,0,0,0,0,0,0,0,"ARIAL")
SelectObject_(hdc, hfont)
TextOut_(hdc, 310, 100,"Pure Basic", 10)
DeleteObject_(hfont)
ReleaseDC_(WindowID(), hdc)
Repeat
EventID.l = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
End
Your best bet might be to create your own custom control.
I may look like a mule, but I'm not a complete ass.
Sorry
Code: Select all
; Up
;
; Center
;
; Down
Yes?
Make a StringGadget that's small in width, huge in height and add these constants in the flags:
I tried to make one it isn't something special. just the #ES_AUTOVSCROLL is needed...
:roll: (Yes! Even I can help )
Make a StringGadget that's small in width, huge in height and add these constants in the flags:
Code: Select all
#PB_String_MultiLine|#ES_AUTOVSCROLL
:roll: (Yes! Even I can help )
I think I understand; you wish to position the text vertically within a string gadget? I.e. sometimes place the text at the top, sometimes in the middle etc?
Unfortunately I do not think that there is a simple style-flag to achieve this. You can certainly set the left and right margins, but I haven't as yet come across a flag to set a vertical margin. I'll have a scan through MSDN in a minute.
I actually needed this myself a while ago, but everytime I repositioned the text within the gadget (through some custom drawing), the cursor would not follow! I ended up cheating.
Basically, create some kind of container gadget and paint it to look like the string gadget's background. Then simply position a borderless string gadget at the appropriate position within the container to make it look like a single edit control and that's it - job done!
If I've understood you correctly, and if I've time, I'll put together a small example for you later on.
Unfortunately I do not think that there is a simple style-flag to achieve this. You can certainly set the left and right margins, but I haven't as yet come across a flag to set a vertical margin. I'll have a scan through MSDN in a minute.
I actually needed this myself a while ago, but everytime I repositioned the text within the gadget (through some custom drawing), the cursor would not follow! I ended up cheating.
Basically, create some kind of container gadget and paint it to look like the string gadget's background. Then simply position a borderless string gadget at the appropriate position within the container to make it look like a single edit control and that's it - job done!
If I've understood you correctly, and if I've time, I'll put together a small example for you later on.
I may look like a mule, but I'm not a complete ass.
How about something like this...
Code: Select all
; ************************************************
; Code: Verticaly and Horizontaly centered text
; in a multiline StringGadget
; Author: Sparkie
; Date: December 20, 2005
; OS: Windows only
; ************************************************
; ************************************************
; Procedure: Center text in Multiline StringGadget
; ************************************************
Procedure StringGadgetVCenter(gadNum)
;--> Get line count of StringGadget
lineCount = SendMessage_(GadgetID(gadNum), #EM_GETLINECOUNT, 0, 0)
myText$ = GetGadgetText(gadNum)
;--> Get width and height of text on one line
hdc = GetDC_(GadgetID(gadNum))
GetTextExtentPoint32_(hdc, myText$, Len(myText$), @textXY.SIZE)
ReleaseDC_(GadgetID(gadNum), hdc)
;--> Set rect coordinates for StringGadget
eRect.RECT
eRect\left = 0
eRect\top = (GadgetHeight(gadNum) - textXY\cy*lineCount) / 2
eRect\right = GadgetWidth(gadNum) - (eRect\left * 2)
eRect\bottom = eRect\top + textXY\cy*lineCount
SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
EndProcedure
; ************************************************
; Main Window
; ************************************************
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Centered Text") And CreateGadgetList(WindowID(0))
;--> #ES_CENTER will not work with a singleline StringGadget on Win95/NT4
StringGadget(0, 50, 10, 200, 80, "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget", #PB_String_MultiLine | #ES_CENTER)
StringGadgetVCenter(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Now that sound like a challenge to me!
Here ya go...
***EDIT: It now scrolls correctly and accounts for any scrollbars! -Twit that I am!
Here ya go...
***EDIT: It now scrolls correctly and accounts for any scrollbars! -Twit that I am!
Code: Select all
; ************************************************
; Code: Verticaly and Horizontaly centered text
; in a multiline StringGadget
; Author: Sparkie + srod! (But mostly Sparkie!)
; Date: December 20, 2005
; OS: Windows only
; ************************************************
; ************************************************
; Procedure: Center text in Multiline StringGadget
; ************************************************
Procedure StringGadgetVCenter(gadNum)
;--> Get line count of StringGadget
lineCount = SendMessage_(GadgetID(gadNum), #EM_GETLINECOUNT, 0, 0)
myText$ = GetGadgetText(gadNum)
;--> Get width and height of text on one line
hdc = GetDC_(GadgetID(gadNum))
GetTextExtentPoint32_(hdc, myText$, Len(myText$), @textXY.SIZE)
ReleaseDC_(GadgetID(gadNum), hdc)
eRect.RECT
;--> Set rect coordinates for StringGadget
;The following line is used to set the left and right boundaries and takes any scrollbars
;into account.
getclientrect_(GadgetID(gadNum), eRect)
eRect\top = (GadgetHeight(gadNum) - textXY\cy*lineCount) / 2
eRect\bottom = eRect\top + textXY\cy*lineCount
;Check if the rectangle is too high.
if eRect\bottom<gadgetheight(gadNum)
SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
endif
EndProcedure
; ************************************************
; Main Window
; ************************************************
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Centered Text") And CreateGadgetList(WindowID(0))
;--> #ES_CENTER will not work with a singleline StringGadget on Win95/NT4
StringGadget(0, 50, 10, 200, 80, "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget", #PB_String_MultiLine | #ES_CENTER|#WS_VSCROLL|#ES_AUTOVSCROLL)
StringGadgetVCenter(0)
numlines = sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
Repeat
eventid=waitwindowevent()
if eventtype() = #PB_EventType_Change and eventgadgetid() = 0 and numlines<>sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
numlines = sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
StringGadgetVCenter(0)
endif
Until eventid = #PB_Event_CloseWindow
EndIf
End
I may look like a mule, but I'm not a complete ass.
-
- New User
- Posts: 1
- Joined: Wed Dec 28, 2005 8:44 am
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
* BUMP *
Just needed this and took me a while to find it as it seems like a rather rare request. While I tested this I noticed some flaws. First off, the code doesn't take the currently selected font into account wich makes the lines get splitted into 2 or more blocks. Second, if you made this fix you also need to add the 2 x 2 pixel border when calculating 'eRect\bottom' or it causes the same problem.
Here's my fixed version for future searches:
Just needed this and took me a while to find it as it seems like a rather rare request. While I tested this I noticed some flaws. First off, the code doesn't take the currently selected font into account wich makes the lines get splitted into 2 or more blocks. Second, if you made this fix you also need to add the 2 x 2 pixel border when calculating 'eRect\bottom' or it causes the same problem.
Here's my fixed version for future searches:
Code: Select all
Procedure StringGadgetVCenter(GadgetID)
hwndEdit = GadgetID(GadgetID)
LineCount = SendMessage_(hwndEdit,#EM_GETLINECOUNT, 0, 0)
hdc = GetDC_(hwndEdit)
SelectObject_(hdc,GetGadgetFont(0))
GetTextExtentPoint32_(hdc,"ABC",3,fsz.SIZE)
ReleaseDC_(hwndEdit,hdc)
GetClientRect_(hwndEdit,eRect.RECT)
eRect\top = (GadgetHeight(GadgetID) - fsz\cy * LineCount) / 2
eRect\bottom = eRect\top + (fsz\cy * LineCount) + 4
If eRect\bottom < GadgetHeight(GadgetID)
SendMessage_(hwndEdit,#EM_SETRECT,0,eRect)
EndIf
EndProcedure
Text$ = "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget"
OpenWindow(0,0,0,300,200,"Edit Control VCenter",#WS_SYSMENU | #WS_CAPTION | 1)
CreateGadgetList(WindowID(0))
StringGadget(0,10,10,280,180,Text$,#ES_MULTILINE | #ES_CENTER )
SetGadgetFont(0,LoadFont(0,"Arial",12))
StringGadgetVCenter(0)
LinesNum = SendMessage_(GadgetID(0), #EM_GETLINECOUNT,0,0)
Repeat
EventID = WaitWindowEvent()
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change And LinesNum <> SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
LinesNum = SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
StringGadgetVCenter(0)
EndIf
EndSelect
Until EventID = #PB_Event_CloseWindow
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?