B4J Question How to save and read font for a label?

jransom2

Member
Licensed User
Longtime User
How do you save font information to a file and read it back in for user customization of a label?

Here is where I am at:

From TextFiles example:

Private Sub SaveSettings
File.WriteString(DataFolder, "text.txt", TextArea1.Text)
File.WriteMap(DataFolder, "settings.txt", _
CreateMap("CheckBox1": CheckBox1.Checked, _
"CheckBox2": CheckBox2.Checked, _
"Saved_Font": f))
End Sub

Private Sub LoadSettings
If File.Exists(DataFolder, "settings.txt") Then
Dim settings As Map = File.ReadMap(DataFolder, "settings.txt")
CheckBox1.Checked = settings.GetDefault("CheckBox1", False)
CheckBox2.Checked = settings.GetDefault("CheckBox2", False)
lblWelcome.font = settings.GetDefault("Saved_Font", "")
End If

The problem is that this will error out during compile.

What is the correct way to do this?

Thanks for your help.
 

Daestrum

Expert
Licensed User
Longtime User
Not tried but I guess in the sub SaveSettings
B4X:
"Saved_Font": f

May work better as
B4X:
"Saved_Font": lblWelcome.Font

So you store the font assigned to the label.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

You can use KeyValueStore and store the family name and font size:
B4X:
KVS.Put("Saved_Font", CreateMap("Name": f.FamilyName, "Size": f.Size))

B4X:
Dim m As Map = KVS.Get("Saved_Font")
Dim f As Font = fx.CreateFont(m.Get("Name"), m.Get("Size"), False, False)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…