Results 1 to 3 of 3

Thread: How do I change fonts in Controls?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Location
    Austin ,TX USA
    Age
    70
    Posts
    2
    Rep Power
    0

    How do I change fonts in Controls?

    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

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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, maybe your vote can help make it happen. In the meantime you can use the approach above.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Location
    Austin ,TX USA
    Age
    70
    Posts
    2
    Rep Power
    0
    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

Similar Threads

  1. TBGL - please help with testing fonts
    By Petr Schreiber in forum TBGL General
    Replies: 3
    Last Post: 13-06-2009, 21:33
  2. AMD: change all
    By ErosOlmi in forum Technology
    Replies: 0
    Last Post: 07-10-2008, 20:55
  3. JPG IMG controls... (Why is that not here?)
    By ISAWHIM in forum UI (User Interface)
    Replies: 3
    Last Post: 26-09-2008, 04:25
  4. textures and fonts
    By sandyrepope in forum TBGL General
    Replies: 1
    Last Post: 28-03-2008, 09:22
  5. Deleting Controls
    By catventure in forum thinBasic General
    Replies: 16
    Last Post: 08-11-2005, 02:10

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •