Remember Checkbox on form close and open

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
leroy_002
Posts: 3
Joined: Thu Jun 20, 2019 2:01 am

Remember Checkbox on form close and open

Post by leroy_002 » Thu Aug 29, 2019 9:02 am

Hello,

I added autocomplete to my text box's but some user's done want to use autocomplete so I added a checkbox to turn autocomplete on or off

I was wondering if there was a way to remember that the checkbox was checked on the next form load so the user doesn't have to constantly check the turn off box

jvierra
Posts: 13901
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Remember Checkbox on form close and open

Post by jvierra » Thu Aug 29, 2019 10:48 am

Here is a quick example of how to remember settings.

Code: Select all

   # at beginning of script.
    add-type -AssemblyName Microsoft.VisualBasic

# in Form Load
    If ($size = [Microsoft.VisualBasic.Interaction]::GetSetting('CsvEdit', 'MainForm', 'Size', $size)) {
        $form1.Size = $size
        $form1.Left = ([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width -  $form1.Width)/2
        $form1.Top  = ([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height - $form1.Height)/2
    }
    If ($csvFile = [Microsoft.VisualBasic.Interaction]::GetSetting('CsvEdit', 'MainForm', 'LinkList', 'visited.csv')) {
        $textboxCsvFile.Text = $csvFile
    }

You can also just save the setting to a simple file and read it back when the form opens.

Locked