anakic/Jot

Not working for Windows Forms

ElektroStudios opened this issue · 2 comments

Hey, I'm new using this lib. I just took the example from the readme.md and adapted it to use for a Form isntead of a WPF Window. The next code pretends to save and restore the location of a Form, but it does not restore the location...

    Public Sub New()
        MyClass.InitializeComponent()

        Tracker.Configure(Me).IdentifyAs(NameOf(Form1)).
                AddProperties(Of Form)(Function(x As Form) x.Location).
                RegisterPersistTrigger(NameOf(Form.LocationChanged)).
                Apply()

    End Sub

I'm missing something to do?.

Nevermind. I just didn't knew that the values are restored when calling the "Apply" method, so I must call it outside the constructor (in the Form.Load event for example) and then it works perfectly.

Hey! Yes, winforms ignore location settings that are applied in the constructor.

I wanted to note a few other things:

  • you can also add properties by name, e.g. AddProperties(NameOf(Form1.Location))
  • if it's a form you're tracking, it's enough to call Tracker.Configure(Me).Apply() since a configuration for tracking forms is included by default in Jot. This configuration handles some edge cases like persisting a minimized form, or restoring a form that was on a display that is no longer connected.