Ułatw sobie życie i wrzuć to w rozszerzenia C#
Kopiuj
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
namespace ProjectX
{
public static class Extensions
{
internal static void SetBool(this RegistryKey regKey, string entryName, bool boolValue)
{
regKey.SetValue(entryName, (boolValue ? 1 : 0), RegistryValueKind.DWord);
}
internal static bool GetBool(this RegistryKey regKey, string entryName, bool defaultValue)
{
try
{
int result = (int)regKey.GetValue(entryName, defaultValue ? 1 : 0);
return result != 0 ? true : false;
}
catch (System.Exception)
{
return defaultValue;
}
}
}
}
I potem przez RegistryKey czytaj i ustawiaj wartości
Kopiuj
regKey.SetBool("Opcja", checkBox1.Checked);
checkBox1.Checked = regKey.GetBool("Opcja", true);