Beispiel #1
0
        public void OnClick(object sender, EventArgs e)
        {
            Control    Con  = (sender as Button);
            MethodInfo Info = GetType().GetMethod(Con.Tag as string);

            Log.Info("Function", "Name=" + (string)Con.Tag);

            if (Info == null)
            {
                Log.Error("Function", "Function not find : " + (string)Con.Tag);
                return;
            }

            Config = EasyServer.GetConf("Config");

            List <string> Params = new List <string>();
            ConfigElement Button = null;;

            foreach (ConfigElement Element in Config.Children.Values)
            {
                if (Element["Tag"].GetString() == Con.Tag as string)
                {
                    Button = Element;
                    break;
                }
            }

            foreach (ConfigElement Element in Button.Children["OnClick"].Children.Values)
            {
                string TagToFind = Element.GetString();
                string TagValue  = GetTag(TagToFind);

                Log.Info("OnClick", TagToFind + " Add value : " + TagValue);

                if (TagValue.Length > 0)
                {
                    Params.Add(TagValue);
                }
            }


            if (Info.GetParameters().Length != Params.Count)
            {
                Log.Error("OnClick", "Function :" + Con.Tag + ", Invalid Params Count : Function=" + Info.GetParameters().Length + ",Xml=" + Params.Count);
                return;
            }

            if (Info != null)
            {
                Info.Invoke(this, Params.ToArray());
            }
        }
Beispiel #2
0
        public void LoadConfig()
        {
            if (!EasyServer.InitConfig("Configs/Conf.xml", "Config"))
            {
                return;
            }

            Config = EasyServer.GetConf("Config");

            foreach (KeyValuePair <string, ConfigElement> Elements in Config.Children)
            {
                ConfigElement Element = Elements.Value;

                Log.Info("Control", "New control : " + Elements.Key);

                if (Elements.Key == "Master")
                {
                    string Name   = Element["Name"].GetString("Launcher");
                    int    W      = Element["Width"].GetInt(100);
                    int    H      = Element["Height"].GetInt(100);
                    int    Resize = Element["Resize"].GetInt(100);

                    Log.Info("Scale", "X=" + W + ",Y=" + H);

                    this.Name = Name;
                    this.Text = Name;

                    this.AutoScaleDimensions = new SizeF(W, H);
                    this.AutoScaleMode       = AutoScaleMode.Font;
                    this.FormBorderStyle     = Resize <= 0 ? FormBorderStyle.FixedToolWindow : FormBorderStyle.Sizable;
                    this.ClientSize          = new Size(Width, Height);
                    this.Size = new System.Drawing.Size(W, H);
                }
                else
                {
                    string   Type         = Element["Type"].GetString("label");
                    string   Name         = Element["Name"].GetString("Unknown");
                    string   Text         = Element["Text"].GetString("");
                    int      W            = Element["Width"].GetInt(100);
                    int      H            = Element["Height"].GetInt(20);
                    int      X            = Element["X"].GetInt(0);
                    int      Y            = Element["Y"].GetInt(0);
                    int      Transparency = Element["Tranparency"].GetInt(0);
                    string   Tag          = Element["Tag"].GetString("");
                    string[] BackColor    = Element["BackColor"].GetString("1,1,1").Split(',');
                    string[] ForeColor    = Element["ForeColor"].GetString("255,255,255").Split(',');

                    Log.Info("Tag", "Tag=" + Tag);

                    Control Con;
                    switch (Type)
                    {
                    case "textArea":
                        int Masked = Element["Masked"].GetInt(0);

                        if (Masked == 0)
                        {
                            Con = new TextBox();
                        }
                        else
                        {
                            Con = new MaskedTextBox();
                        }

                        if (Transparency > 0)
                        {
                            (Con as TextBoxBase).BorderStyle = BorderStyle.None;
                        }

                        break;

                    case "Label":
                        Con = new Label();
                        break;

                    case "button":
                        Con        = new Button();
                        Con.Click += new EventHandler(this.OnClick);
                        break;

                    case "picture":

                        Con = new PictureBox();
                        (Con as PictureBox).ImageLocation = Element["Image"].GetString();
                        (Con as PictureBox).InitialImage  = null;
                        break;

                    default:
                        Con = new Label();
                        break;
                    }

                    Con.Name     = Name;
                    Con.Text     = Text;
                    Con.Location = new System.Drawing.Point(X, Y);
                    Con.Size     = new System.Drawing.Size(W, H);

                    if (Con is Label)
                    {
                        (Con as Label).AutoSize = true;
                    }

                    Con.Tag = Tag;

                    if (BackColor.Length >= 3)
                    {
                        Con.BackColor = Color.FromArgb(int.Parse(BackColor[0]), int.Parse(BackColor[1]), int.Parse(BackColor[2]));
                    }

                    if (ForeColor.Length >= 3)
                    {
                        Con.ForeColor = Color.FromArgb(int.Parse(ForeColor[0]), int.Parse(ForeColor[1]), int.Parse(ForeColor[2]));
                    }

                    _Controls.Add(Con);
                }
            }
        }