User Tools

Site Tools


Sidebar

Multimedia

k23:k23.2:k23.2.3:start

23.2.3 FontChooser

This component allows you to quickly select a font from the fonts installed in the system and assign it to a text processing or text displaying component.

23.2.3.1 Properties

You will almost always call up the FontChooser component in a separate modal form. You can overwrite the default settings in individual properties, but this does not seem necessary. The default value is True for all three properties and ensures that relevant information about the fonts is displayed optimally in the FontChooser component:

  • FontChooser.ShowLabel = True
  • FontChooser.ShowPreview = True
  • FontChooser.ShowStyle = True

The FontChooser.FixedOnly property is an exception. It specifies whether only fonts with a fixed font size are displayed in the selection. This property should be freely selectable. However, the processing of the return value of the FontChooser component is probably the most interesting. The following assignment transfers the selected font to the font property of a component:

Komponente.Font = Font[FontChooser.SelectedFont]

23.2.3.2 Example

The project presented implements the theoretical elements mentioned above. It consists of the start form, the 2nd form with the FontChooser component and a module. As the source text is quite compact, both source texts are given.

Startformular

Figure 23.2.3.2.1: Start form

Source code 1:

' Gambas class file
Private sTextAreaFont As String
 
Public Sub Form_Open()
    FMain.Center()
    FMain.Resizable = False
    MG.bShowLabel = True
    MG.bShowPreView = True
    MG.bShowStyle = True
    cboxFixedFont.Value = False  
'-- Save original font
    sTextAreaFont = TextArea1.Font.ToString()
End
 
Public Sub btnDisplayFC_Click()
   If cboxFixedFont.Value = True Then
      MG.bFixedOnly = True '-- The default value is overwritten
   Endif
 
   FormFC.ShowModal()
 
   If MG.SelectedFont <> Null Then
      TextArea1.Font = Font[MG.SelectedFont]
   Endif
End
 
Public Sub btnReset_Click()
    TextArea1.Font = Font[sTextAreaFont]
    cboxFixedFont.Value = False
End
 
Public Sub btnClose_Click()
    FMain.Close()
End

A module has been inserted to maintain the relevant variables in one place:

' Gambas module file
 
Public bShowLabel As Boolean
Public bShowPreView As Boolean
Public bShowStyle As Boolean
Public bFixedOnly As Boolean
 
Public SelectedFont As String

Form 2

Auswahl

Figure 23.2.3.2.2: Font selection (font family, font style and font size)

  • You can specify the font size relatively in the integer range -4 ≤ S ≤ +16 - default size Size=9, corresponds to S=0 - or absolutely in size specifications.

Source text 3:

' Gambas class file
 
Public Sub Form_Open()
    FormFC.Resizable = False
    FontChooser1.ShowLabel = MG.bShowLabel
    FontChooser1.ShowPreview = MG.bShowPreView
    FontChooser1.ShowStyle = MG.bShowStyle
    FontChooser1.FixedOnly = MG.bFixedOnly
End
 
Public Sub btnCancel_Click()
    MG.SelectedFont = Null
    FormFC.Close()
End
 
Public Sub btnSetFont_Click()
    MG.SelectedFont = FontChooser1.SelectedFont '-- Alternative:  FontChooser1.Value
    FormFC.Close()
End

As only fonts with a fixed width can be selected, only these fonts are displayed in the font selection component. With the selected properties, the font image now looks like this:

TextFont

Figure 23.2.3.2.3: TextArea with the selected font properties

With an elegant click on the button labelled R, you can reassign the saved original font of the TextArea to the font of the TextArea and reset the checkbox to the initial value for displaying all fonts.

23.3.3.3 Download

Article

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.2/k23.2.3/start.txt · Last modified: 24.02.2024 by emma

Page Tools