Beispiel #1
0
        private void preencheLabels(Hotkeys hotkeys)
        {
            var nomeAtalho1 = default(string);
            var nomeAtalho2 = default(string);

            if (hotkeys != null)
            {
                nomeAtalho1 = hotkeys.Atalho1;
                nomeAtalho2 = hotkeys.Atalho2;
            }
            var Atalhos = nomeAtalho1 + (nomeAtalho2 == "" ? nomeAtalho2 : " + " + nomeAtalho2);

            lblPlayPause.Text = "Play/Pause: " + Atalhos + " + Enter";
            lblProxima.Text   = "Próxima Música: " + Atalhos + " +   Direita";
            lblAnterior.Text  = "Música Anterior: " + Atalhos + " +  Esquerda";
            lblVolDown.Text   = "Diminuir Volume: " + Atalhos + " +  Baixo";
            lblVolUp.Text     = "Aumentar Volume: " + Atalhos + " +  Cima";

            if (hotkeys != null)
            {
                Type t = hotkeys.GetType();

                PropertyInfo[] props = t.GetProperties();
                foreach (var c in grbExecutar.Controls)
                {
                    if (c is Label)
                    {
                        var value = props.FirstOrDefault(p => p.Name == ((Label)c).Name.Replace("lbl", "")).GetValue(hotkeys);
                        if (value != null)
                        {
                            var exeName = default(string);
                            exeName         = Path.GetFileName(value.ToString());
                            ((Label)c).Text = $"Tecla {((Label)c).Name.Replace("lbl", " ")} : {exeName}";
                        }
                    }
                }
                foreach (var c in grbTextos.Controls)
                {
                    if (c is Label)
                    {
                        var value = props.FirstOrDefault(p => p.Name == ((Label)c).Name.Replace("lbl", "")).GetValue(hotkeys);
                        if (value != null)
                        {
                            var valueDShow = props.FirstOrDefault(p => p.Name == ((Label)c).Name.Replace("lbl", "cb")).GetValue(hotkeys);
                            var dShow      = default(bool);
                            if (valueDShow != null)
                            {
                                bool.TryParse(valueDShow.ToString(), out dShow);
                            }
                            if (dShow)
                            {
                                ((Label)c).Text = ((Label)c).Name.Replace("lblNumPad", "NumPad ") + ": ••••••";
                            }
                            else
                            {
                                ((Label)c).Text = ((Label)c).Name.Replace("lblNumPad", "NumPad ") + ": " + value.ToString();
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static Hotkeys LerXML(string arquivo)
        {
            var xml       = XElement.Load(arquivo);
            var Shortcuts = (from Shortcut in xml.Elements("Shortcuts")
                             select Shortcut).FirstOrDefault();

            var Shortcut1 = Shortcuts.Element("Shortcut1"); //.Value.ToString();
            var Shortcut2 = Shortcuts.Element("Shortcut2"); //.Value.ToString();
            //var b = Shortcuts.Element("Shortcut_b");
            //var c = Shortcuts.Element("Shortcut_c");
            //var f = Shortcuts.Element("Shortcut_f");
            //var n = Shortcuts.Element("Shortcut_n");
            //var o = Shortcuts.Element("Shortcut_o");
            //var p = Shortcuts.Element("Shortcut_p");
            //var s = Shortcuts.Element("Shortcut_s");
            //var v = Shortcuts.Element("Shortcut_v");
            //var w = Shortcuts.Element("Shortcut_w");
            //var g = Shortcuts.Element("Shortcut_g");
            //var i = Shortcuts.Element("Shortcut_i");
            //var e = Shortcuts.Element("Shortcut_e");
            //var u = Shortcuts.Element("Shortcut_u");
            var retorno = new Hotkeys();

            if (Shortcut1 != null)
            {
                retorno.Atalho1 = Shortcut1.Value.ToString();
            }
            else
            {
                retorno.Atalho1 = string.Empty;
            }
            if (Shortcut2 != null)
            {
                retorno.Atalho2 = Shortcut2.Value.ToString();
            }
            else
            {
                retorno.Atalho2 = string.Empty;
            }
            Type t = retorno.GetType();

            PropertyInfo[] props = t.GetProperties();
            foreach (var item in props)
            {
                if (item.Name.Contains("Atalho"))
                {
                    continue;
                }
                var value = Shortcuts.Element("Shortcut_" + item.Name.ToLower());
                if (value != null)
                {
                    SetValue(retorno, item, value.Value.ToString());
                }
                else
                {
                    SetValue(retorno, item, string.Empty);
                }
            }

            #region old Coment
            //if (b != null)
            //{
            //    retorno.B = b.Value.ToString();
            //}
            //else
            //{
            //    retorno.B = string.Empty;
            //}
            //if (c != null)
            //{
            //    retorno.C = c.Value.ToString();
            //}
            //else
            //{
            //    retorno.C = string.Empty;
            //}
            //if (f != null)
            //{
            //    retorno.F = f.Value.ToString();
            //}
            //else
            //{
            //    retorno.F = string.Empty;
            //}
            //if (n != null)
            //{
            //    retorno.N = n.Value.ToString();
            //}
            //else
            //{
            //    retorno.N = string.Empty;
            //}
            //if (o != null)
            //{
            //    retorno.O = o.Value.ToString();
            //}
            //else
            //{
            //    retorno.O = string.Empty;
            //}
            //if (s != null)
            //{
            //    retorno.S = s.Value.ToString();
            //}
            //else
            //{
            //    retorno.S = string.Empty;
            //}
            //if (p != null)
            //{
            //    retorno.P = p.Value.ToString();
            //}
            //else
            //{
            //    retorno.P = string.Empty;
            //}
            //if (v != null)
            //{
            //    retorno.V = v.Value.ToString();
            //}
            //else
            //{
            //    retorno.V = string.Empty;
            //}
            //if (w != null)
            //{
            //    retorno.W = w.Value.ToString();
            //}
            //else
            //{
            //    retorno.W = string.Empty;
            //}
            //if (g != null)
            //{
            //    retorno.G = g.Value.ToString();
            //}
            //else
            //{
            //    retorno.G = string.Empty;
            //}
            //if (i != null)
            //{
            //    retorno.I = i.Value.ToString();
            //}
            //else
            //{
            //    retorno.I = string.Empty;
            //}
            //if (e != null)
            //{
            //    retorno.E = e.Value.ToString();
            //}
            //else
            //{
            //    retorno.E = string.Empty;
            //}
            //if (u != null)
            //{
            //    retorno.U = u.Value.ToString();
            //}
            //else
            //{
            //    retorno.U = string.Empty;
            //}
            #endregion

            return(retorno);
        }