/// <summary> /// Sets the value of <paramref name="keyName"/> in <paramref name="registryKey"/> to '1' (REG_SZ) if /// <paramref name="chk"/>'s IsChecked is equal to true, otherwise sets it to '0' (REG_SZ). /// This behaviour is reversed if <paramref name="inverse"/> is set to true. /// Each <paramref name="chk" /> has a tag associated with it, which when set to 1 (HasUserInteracted) /// will then be saved to registry, otherwise it'll be ignored. /// </summary> /// <param name="registryKey"></param> /// <param name="chk"></param> /// <param name="keyName"></param> /// <param name="inverse"></param> public static void SetStringValue(this RegistryKey registryKey, CheckBox chk, string keyName, bool inverse = false) { if (chk.HasUserInteracted()) { string val = inverse ? Utils.ReversedBoolToString(chk.IsChecked) : Utils.BoolToString(chk.IsChecked); registryKey.SetValue(keyName, val); } }
/// <summary> /// Sets the value of <paramref name="keyName"/> in <paramref name="registryKey"/> to 1 (REG_DWORD) if /// <paramref name="chk"/>'s IsChecked is equal to true, otherwise sets it to 0 (REG_DWORD). /// This behaviour is reversed if <paramref name="inverse"/> is set to true. /// Each <paramref name="chk" /> has a tag associated with it, which when set to 1 (HasUserInteracted) /// will then be saved to registry, otherwise it'll be ignored. /// </summary> /// <param name="registryKey"></param> /// <param name="chk"></param> /// <param name="keyName"></param> /// <param name="inverse"></param> internal static void SetValue(this RegistryKey registryKey, CheckBox chk, string keyName, bool inverse = false) { if (chk.HasUserInteracted()) { registryKey.SetValue(keyName, chk.IsChecked, inverse); } }
/// <summary> /// Creates a sub-key with name (if it doesn't exists) <paramref name="keyName"/> under <paramref name="registryKey"/> if /// <paramref name="chk"/>'s IsChecked is equal to true, otherwise it deletes it (if present). /// Each <paramref name="chk" /> has a tag associated with it, which when set to 1 (HasUserInteracted) /// will then be saved to registry, otherwise it'll be ignored. /// </summary> /// <param name="registryKey"></param> /// <param name="chk"></param> /// <param name="keyName"></param> internal static void SetSubKey(this RegistryKey registryKey, CheckBox chk, string keyName) { if (chk.HasUserInteracted()) { registryKey.SetSubKey(keyName, chk.IsChecked); } }