Page 1 of 1
Fonts in the EditorGadget
Posted: Tue Jul 21, 2009 2:33 am
by albert_redditt
How do you make the font bold type??????
I don't see anyway of manipulating the font in any of the gadgets.
Posted: Tue Jul 21, 2009 3:07 am
by netmaestro
I'm sorry I have little time tonight for a complete solution, otherwise I'd post an example. However, if you dig into MSDN for EM_SETCHARFORMAT I believe you'll find what you need. (for Windows, of course. Dunno for other OS's.)
Posted: Tue Jul 21, 2009 7:36 am
by rrpl
Eh Try,
SetGadgetFont(#Gadget, FontID)
Search for SetGadgetFont in the PB help, they have an example as well.
Don't forget you need to load the font first.

Posted: Tue Jul 21, 2009 8:07 pm
by netmaestro
I assumed something more involved of course, as setting font, size, etc. for selected range. But SetGadgetFont may be all you need, I really can't tell from your question which you are looking for.
Re:
Posted: Wed May 09, 2018 9:22 am
by mestnyi
netmaestro wrote:I assumed something more involved of course, as setting font, size, etc. for selected range.
Here it is necessary for me, how to do this?
http://www.purebasic.fr/english/viewtop ... 50#p522021
If there are examples of better offer.
Re: Fonts in the EditorGadget
Posted: Wed May 09, 2018 6:19 pm
by mk-soft
You can use rtf (Rich Text Format). Wiki:
https://en.wikipedia.org/wiki/Rich_Text_Format
Windows Only
Code: Select all
;-TOP
; *****************************************************************************
; AddTextRTF by mk-soft, v1.05, 27.03.2018
CompilerIf #PB_Compiler_Version < 550
Procedure UTF8(Text.s)
Protected *mem = AllocateMemory(StringByteLength(Text, #PB_UTF8) + 1)
If *mem
PokeS(*mem, Text, -1, #PB_UTF8)
EndIf
ProcedureReturn *mem
EndProcedure
CompilerEndIf
Procedure AddTextRTF(Gadget, Text.s , NewLine=#False)
If Left(Text, 5) <> "{\rtf"
Text = "{\rtf " + Text + "}"
EndIf
If NewLine
Text = Left(Text, Len(text) - 1) + "\line}"
EndIf
CompilerIf #PB_Compiler_Unicode
Protected hEdit = GadgetID(Gadget)
Protected ndx = GetWindowTextLength_(hEdit)
Protected *szBuffer = UTF8(Text)
SendMessage_(hEdit, #EM_SETSEL, ndx, ndx)
SendMessage_(hEdit, #EM_REPLACESEL, 0, *szBuffer)
FreeMemory(*szBuffer)
CompilerElse
AddGadgetItem(Gadget, -1 , Text)
CompilerEndIf
EndProcedure
; *****************************************************************************
;-
Define.s rtf1, rtf2
;rtf1 = "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par}"
rtf1 = "This is some {\b bold} text."
rtf2 = "{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}"
rtf2 + "{\colortbl;\red0\green0\blue255;\red255\green0\blue;}"
rtf2 + "This line is the Default color\line"
rtf2 + "\cf2"
rtf2 + "\tab This line is red And has a tab before it\line"
rtf2 + "\cf1"
rtf2 + "\b This line is the blue color And bold"
rtf2 + "}"
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 306, 133)
AddTextRTF(0, rtf1, 1)
AddTextRTF(0, rtf2, 1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Update...

Re: Fonts in the EditorGadget
Posted: Sat May 12, 2018 3:10 pm
by eJan
You can try with these, thanks to: Srod & netmaestro.
Code: Select all
; Srod: http://www.purebasic.fr/english/viewtopic.php?p=164184#164184
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 270, 160, "TextGadget", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 250, 20, "TextGadget Standard (Left)")
font = SendMessage_(GadgetID(0), #WM_GETFONT, 0, 0)
GetObject_(font, SizeOf(LOGFONT), lg.LOGFONT)
lg\lfWeight = #FW_BOLD
font = CreateFontIndirect_(lg)
SendMessage_(GadgetID(0), #WM_SETFONT, font, 1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
DeleteObject_(font)
Code: Select all
; netmaestro: http://www.purebasic.fr/english/viewtopic.php?p=164013#164013
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 250, 20, "TextGadget Standard (Left) [BOLD]")
TextGadget(1, 10, 70, 250, 20, "TextGadget Center", #PB_Text_Center)
TextGadget(2, 10, 40, 250, 20, "TextGadget Right", #PB_Text_Right)
TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
SetGadgetFont(0, GetStockObject_(#BOLD_FONTTYPE))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf