Bill Roth
09-03-2012, 19:16
My apologies if I missed it in the manual, but after several hours of reading, I cannot seem to find any way to change the font in a text box. The application will be a Com Terminal with the comm data going to a text box. The text box font needs to be Courier New.
Likewise, I see no way to change the font in a ListBox or other controls. What am I missing?
Thanks,
Bill
Petr Schreiber
09-03-2012, 20:45
Hi Bill,
welcome to the forum, and thanks for interesting question. You can achieve what you need using the CONTROL SEND message:
Uses "UI"
' -- ID numbers of controls
Begin ControlID
%bClose
%tbTerminalListing
End ControlID
Begin Const
%MAIN_WIDTH = 320
%MAIN_HEIGHT = 240
End Const
' -- Create dialog here
Function TBMain()
Local hDlg As DWord
Dialog New Pixels, 0, "Font demo",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
' -- Place controls here
Control Add Textbox, hDlg, %tbTerminalListing, "Hello Bill, this is Courier!", 5, 5, %MAIN_WIDTH-10, %MAIN_HEIGHT-40
' -- Font_Create will define new font,
' -- the Resource keyword will make sure
' -- it will Get deleted after program ends
Dim hFontCourier As DWord Resource = Font_Create("Courier New", 9)
' -- This message sent to the item will set the font
Control Send hDlg, %tbTerminalListing, %WM_SETFONT, hFontCourier, 0
Control Add Button, hDlg, %bClose, "Click to close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25, Call cbCloseButton
Dialog Show Modal hDlg, Call cbDialog
End Function
' -- Callback for dialog
CallBack Function cbDialog()
' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Case %WM_COMMAND
' -- You can handle controls here
'SELECT CASE CBCTL
'
' CASE ...
' IF CBCTLMSG = ... THEN
'
' END IF
'
'END SELECT
Case %WM_CLOSE
' -- Put code to be executed before dialog end here
End Select
End Function
' -- Callback for close button
CallBack Function cbCloseButton()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function
I suggested new feature CONTROL SET FONT (http://www.thinbasic.com/community/project.php?issueid=256), maybe your vote can help make it happen. In the meantime you can use the approach above.
Petr
Bill Roth
16-03-2012, 22:49
Hi Petr,
Thanks so much. Ill add this to the other list of tricks I have noted.
And I agree that a Control Set Font feature would make things easier as I am sure it is common to use other than the default font in Memo Boxes, List boxes, etc.
Thanks again,
Bill