B4J Question How to get Font Famyly and style

Discussion in 'B4J Questions' started by tanush62, Aug 10, 2019.

  1. tanush62

    tanush62 New Member

    I know how to set Font (family, style, size)

    Sub Process_Globals
    Public lbl1, lbl2 As B4XView
    Private xfont As B4XFont


    End Sub

    Sub Slider2_ValueChange (Value As Double)
        xfont = fx.CreateFont(nfont2, fsize2, 
        lbl2.Font = xfont
    End Sub
    But how to get Family and style (bold, italic) in code from existing label? I want to read them from already defined label. How to extract them from variable like xfont?
  2. Erel

    Erel Administrator Staff Member Licensed User

    lbl2.Font = xui.CreateFont(fx.CreateFont(...), 20)
    Dim f As Font = lbl2.Font.ToNativeFont
    jimmyF likes this.
  3. tanush62

    tanush62 New Member

    But what about Bold and Italic?
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible. However you can use the label font directly and set it to other views.
  5. tanush62

    tanush62 New Member

    Found the way. Maybe it will be useful to someone.

    Dim af As B4XFont
    Dim xaf As String
    Dim fbold1, fitalic1 As Boolean
    Dim nfont1 As string

        xaf = af    
    'Trick is here, converting B4xfont into string
        Dim xbeg, xend As Int
        xbeg = xaf.IndexOf(
        xend = xaf.IndexOf(
    ", style")
        xbeg = xaf.IndexOf(
        xend = xaf.IndexOf(
    ", size")
        fbold1 = xaf.Contains(
        fitalic1 = xaf.Contains(
    And it works like a charm.
    Last edited: Aug 11, 2019
    xulihang and jimmyF like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice