Exemplo n.º 1
0
        public static void SaveSetting(ButtonEffect effect, ColorMatrix cm, int FontColour)
        {
            string key    = AppController.ApplicationRegistryKeyName;
            string subkey = effect.ToString();

            RegistryKey reg = Registry.CurrentUser.CreateSubKey(key + @"\UserColours\" + subkey);

            if (reg == null)
            {
                return;
            }

            reg.SetValue("FontColour", FontColour);
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    string name = "Matrix"
                                  + i.ToString(System.Globalization.CultureInfo.InvariantCulture)
                                  + j.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    object value = cm.GetType().GetProperty(name).GetValue(cm, null);
                    // Console.WriteLine("i: {0}, j: {1}, value: {2}", i, j, value);
                    reg.SetValue(name, (float)decimal.Parse(value.ToString(), System.Globalization.CultureInfo.InvariantCulture));
                }
            }

            RaiseColoursChangedEvent();
        }
Exemplo n.º 2
0
        private void RandomizeButtonClick(object sender, EventArgs e)
        {
            var cm = new ColorMatrix();

            int numberOfChanges = 5;

            var r = new Random();

            for (int i = 0; i < numberOfChanges; i++)
            {
                int x = r.Next(0, 5);
                int y = r.Next(0, 3);

                string name = "Matrix" + x.ToString(CultureInfo.InvariantCulture) + y.ToString(CultureInfo.InvariantCulture);
                float  val  = (r.Next(-10, 11) / 10F);

                // Update control...
                // (this.Controls[name] as NumericUpDown).Value = val;

                // Or update field.
                cm.GetType().GetProperty(name).SetValue(cm, val, null);
            }

            fontColour = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
            UpdateMatrix(cm);

            SaveSetting();
        }
Exemplo n.º 3
0
        private decimal GetValue(string name)
        {
            // Access the appropriate property of the matrix:
            var     value = currentMatrix.GetType().GetProperty(name).GetValue(currentMatrix, null);
            decimal dvalue;

            if (decimal.TryParse(value.ToString(), out dvalue))
            {
                return(dvalue);
            }
            else
            {
                return(decimal.Zero);
            }
        }
Exemplo n.º 4
0
        private static UserColourSetting GetColourSettingFromRegistry(ButtonEffect effect)
        {
            // Need to be defensively minded as user could change,
            // delete, or change type of registry settings.

            string subkey = AppController.ApplicationRegistryKeyName + @"\UserColours\" + effect.ToString();

            RegistryKey reg = Registry.CurrentUser.OpenSubKey(subkey);

            if (reg == null) // No settings have been defined for this effect
            {
                return(null);
            }

            UserColourSetting setting = new UserColourSetting();

            // User may have changed type of FontColour
            // Using nullable int as any possible integer value could be a valid
            // ToARGB() result (well, I'm assuming it could anyway)

            int?fontColourArgb;

            object value = reg.GetValue("FontColour");

            if (value == null || reg.GetValueKind("FontColour") != RegistryValueKind.DWord)
            {
                fontColourArgb = Color.Black.ToArgb();
            }
            else
            {
                fontColourArgb = (int?)value;
            }

            setting.FontColour = Color.FromArgb((int)fontColourArgb);

            ColorMatrix cm = new ColorMatrix();

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    string name = "Matrix"
                                  + i.ToString(System.Globalization.CultureInfo.InvariantCulture)
                                  + j.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    value = reg.GetValue(name);
                    if (value != null)
                    {
                        float svalue;
                        if (float.TryParse(value.ToString(), out svalue))
                        {
                            cm.GetType().GetProperty(name).SetValue(cm, svalue, null);
                        }
                    }
                }
            }

            setting.Matrix = cm;

            return(setting);
        }