B4J Question Save/Load Colorpicker Selection

ThRuST

Well-Known Member
Licensed User
Longtime User
How to save Colorpicker selectedcolor to a file and load it back so the selected color is highlighted in the colorpicker control? Note: To restore the color in the control. Thanks a bunch.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private ColorPicker1 As ColorPicker
End Sub

Sub AppStart (Form1 As Form, Args() As String)
  
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   
    'Load last selected color.
    If File.Exists(File.DirApp,"color.txt") Then
        Dim color As Int=File.ReadString(File.DirApp,"color.txt")
        ColorPicker1.SelectedColor=fx.Colors.From32Bit(color)
    End If
  
    MainForm.Show

End Sub

Sub ColorPicker1_ValueChanged (Value As Paint)
    'Save selected color
    File.WriteString(File.DirApp,"color.txt",fx.Colors.To32Bit(Value))
End Sub
 
Upvote 0
Top