Czytanie klucza rejestru - wartość bool

0

Cześć,

Mam mały problem z czytaniem klucza w rejestrze. Wartość ta jest bool jednak przy próbie jej odczytania zawsze zwraca false.

Tak wyciągam wartość:

 
domyslny_fullscreen.Checked = Convert.ToBoolean(Registry.GetValue(keyname, "Fullscreen", null));

Z góry dzięki za pomoc

0

Jakiego typu jest klucz, jakie dane zawiera, co zwraca Ci metoda GetValue dla tego klucza.

0

Mam takie metody

 
  private void rejestr_tworzenie(string path, int volume, bool fullscreen)
        {            
            Registry.SetValue(keyname, "SearchingPath", path);
            Registry.SetValue(keyname, "Volume", volume);
            Registry.SetValue(keyname, " Fullscreen", fullscreen);
        }

  private void rejestr_czytanie()
        {
            sciezka_plikow.Text = (string)Registry.GetValue(keyname, "SearchingPath", "Podaj ścieżkę");            
            domyslny_fullscreen.Checked = Convert.ToBoolean(Registry.GetValue(keyname, "Fullscreen", null));
            domyslna_glosnosc.Value = (int)Registry.GetValue(keyname, "Volume", 50);
            
        }

Natomiast

   MessageBox.Show(Convert.ToBoolean(Registry.GetValue(keyname, "Fullscreen", null)).ToString()); 

zwraca false

4

Ułatw sobie życie i wrzuć to w rozszerzenia C#

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

regKey.SetBool("Opcja", checkBox1.Checked);
checkBox1.Checked = regKey.GetBool("Opcja", true);

1 użytkowników online, w tym zalogowanych: 0, gości: 1