Example #1
0
        /// <summary>
        /// The template xml for the screen
        /// </summary>
        /// <param name="FileName"></param>
        public void LoadXML(string FileName)
        {
            int x = 20;
            int y = 0;

            int optionx = 300;
            int optiony = 0;

            string name = "";
            List<string> paramname = new List<string>();
            double rangemin = 0;
            double rangemax = 10;
            double step = 0.001;

            using (XmlReader reader = XmlReader.Create(FileName))
            {
                while (reader.Read())
                {
                    switch (reader.Name.ToUpper())
                    {
                        case "ITEM":

                            break;
                        case "HEAD":
                            y += 30;
                            string heading = reader.ReadString();

                            Label lbl = new Label();
                            lbl.AutoSize = true;
                            lbl.Text = heading;
                            lbl.Location = new Point(x,y);
                            lbl.Font = new Font(FontFamily.GenericSansSerif, 15,FontStyle.Bold);

                            this.Controls.Add(lbl);

                            Controls.MyButton but = new Controls.MyButton();

                            but.Text = "Save";
                            but.Location = new Point(optionx + 100, y);
                            but.Click += new EventHandler(but_Click);
                            this.Controls.Add(but);

                            y = lbl.Location.Y + lbl.Height + 10;

                            LineSeparator ls = new LineSeparator();

                            ls.Width = this.Width - 40;
                            ls.Location = new Point(x,y);

                            ls.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;

                            this.Controls.Add(ls);

                            y = ls.Location.Y + ls.Height;

                            break;
                        case "SUBHEAD":
                            y += 15;

                            optiony = y;
                            optionx = 300;
                            string subhead = reader.ReadString();

                            Label lbl2 = new Label();
                            lbl2.AutoSize = true;
                            lbl2.Text = subhead;
                            lbl2.Location = new Point(x,y);
                            lbl2.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);

                            this.Controls.Add(lbl2);

                            y = lbl2.Location.Y + lbl2.Height;

                            break;
                        case "DESC":
                            y += 2;
                            string desc = reader.ReadString();

                            Label lbl3 = new Label();
                            lbl3.AutoSize = true;
                            lbl3.Text = AddNewLinesToText(desc);
                            lbl3.Location = new Point(x,y);
                            lbl3.Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);

                            this.Controls.Add(lbl3);

                            y = lbl3.Location.Y + lbl3.Height;

                            break;
                        case "FIELDS":
                            if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                if (optiony > y)
                                    y = optiony;
                            }
                            break;
                        case "FIELD":
                            if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                if (name == "" || paramname.Count == 0)
                                    break;

                                Label lbl5 = new Label();
                                //lbl5.AutoSize = true;
                                lbl5.Text = name;
                                lbl5.Location = new Point(optionx, optiony);
                                lbl5.Size = new System.Drawing.Size(90,20);
                                lbl5.Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);
                                lbl5.TextAlign = ContentAlignment.MiddleRight;

                                this.Controls.Add(lbl5);

                                NumericUpDown nud = new NumericUpDown();
                                nud.Location = new Point(optionx + 100, optiony);
                                nud.Size = new System.Drawing.Size(78,20);
                                nud.Maximum = (decimal)rangemax;
                                nud.Minimum = (decimal)rangemin;
                                nud.Increment = (decimal)step;
                                nud.DecimalPlaces = (int)(step.ToString().Length - step.ToString(new System.Globalization.CultureInfo("en-US")).IndexOf('.') -1);
                                nud.Name = paramname[0];

                                this.Controls.Add(nud);

                                optiony += nud.Height;

                                _linkedParams[paramname[0]] = paramname;

                            }
                            else
                            {
                                name = "";
                                paramname = new List<string>();
                                rangemax = 10;
                                rangemin = 0;
                                step = 0.001;
                            }
                            break;
                        case "NAME":
                            name = reader.ReadString();
                            break;
                        case "PARAMNAME":
                            paramname.Add(reader.ReadString());
                            break;
                        case "RANGEMIN":
                            rangemin = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                            break;
                        case "RANGEMAX":
                            rangemax = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                            break;
                        case "STEP":
                            step = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                            break;

                    }
                }
            }

            ThemeManager.ApplyThemeTo(this);

            disableNumericUpDownControls(this);
        }
Example #2
0
        /// <summary>
        /// The template xml for the screen
        /// </summary>
        /// <param name="FileName"></param>
        public void LoadXML(string FileName)
        {
            int x = 20;
            int y = 0;

            int optionx = 300;
            int optiony = 0;

            string        name      = "";
            List <string> paramname = new List <string>();
            double        rangemin  = 0;
            double        rangemax  = 10;
            double        step      = 0.001;

            using (XmlReader reader = XmlReader.Create(FileName))
            {
                while (reader.Read())
                {
                    switch (reader.Name.ToUpper())
                    {
                    case "ITEM":

                        break;

                    case "HEAD":
                        y += 30;
                        string heading = reader.ReadString();

                        Label lbl = new Label();
                        lbl.AutoSize = true;
                        lbl.Text     = heading;
                        lbl.Location = new Point(x, y);
                        lbl.Font     = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold);

                        this.Controls.Add(lbl);

                        Controls.MyButton but = new Controls.MyButton();

                        but.Text     = "Save";
                        but.Location = new Point(optionx + 100, y);
                        but.Click   += new EventHandler(but_Click);
                        this.Controls.Add(but);

                        y = lbl.Location.Y + lbl.Height + 10;

                        LineSeparator ls = new LineSeparator();

                        ls.Width    = this.Width - 40;
                        ls.Location = new Point(x, y);

                        ls.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;

                        this.Controls.Add(ls);

                        y = ls.Location.Y + ls.Height;

                        break;

                    case "SUBHEAD":
                        y += 15;

                        optiony = y;
                        optionx = 300;
                        string subhead = reader.ReadString();

                        Label lbl2 = new Label();
                        lbl2.AutoSize = true;
                        lbl2.Text     = subhead;
                        lbl2.Location = new Point(x, y);
                        lbl2.Font     = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);

                        this.Controls.Add(lbl2);

                        y = lbl2.Location.Y + lbl2.Height;

                        break;

                    case "DESC":
                        y += 2;
                        string desc = reader.ReadString();

                        Label lbl3 = new Label();
                        lbl3.AutoSize = true;
                        lbl3.Text     = AddNewLinesToText(desc);
                        lbl3.Location = new Point(x, y);
                        lbl3.Font     = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);

                        this.Controls.Add(lbl3);

                        y = lbl3.Location.Y + lbl3.Height;

                        break;

                    case "FIELDS":
                        if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            if (optiony > y)
                            {
                                y = optiony;
                            }
                        }
                        break;

                    case "FIELD":
                        if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            if (name == "" || paramname.Count == 0)
                            {
                                break;
                            }

                            Label lbl5 = new Label();
                            //lbl5.AutoSize = true;
                            lbl5.Text      = name;
                            lbl5.Location  = new Point(optionx, optiony);
                            lbl5.Size      = new System.Drawing.Size(90, 20);
                            lbl5.Font      = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);
                            lbl5.TextAlign = ContentAlignment.MiddleRight;

                            this.Controls.Add(lbl5);

                            NumericUpDown nud = new NumericUpDown();
                            nud.Location      = new Point(optionx + 100, optiony);
                            nud.Size          = new System.Drawing.Size(78, 20);
                            nud.Maximum       = (decimal)rangemax;
                            nud.Minimum       = (decimal)rangemin;
                            nud.Increment     = (decimal)step;
                            nud.DecimalPlaces = (int)(step.ToString().Length - step.ToString(new System.Globalization.CultureInfo("en-US")).IndexOf('.') - 1);
                            nud.Name          = paramname[0];

                            this.Controls.Add(nud);

                            optiony += nud.Height;

                            _linkedParams[paramname[0]] = paramname;
                        }
                        else
                        {
                            name      = "";
                            paramname = new List <string>();
                            rangemax  = 10;
                            rangemin  = 0;
                            step      = 0.001;
                        }
                        break;

                    case "NAME":
                        name = reader.ReadString();
                        break;

                    case "PARAMNAME":
                        paramname.Add(reader.ReadString());
                        break;

                    case "RANGEMIN":
                        rangemin = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                        break;

                    case "RANGEMAX":
                        rangemax = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                        break;

                    case "STEP":
                        step = double.Parse(reader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                        break;
                    }
                }
            }

            ThemeManager.ApplyThemeTo(this);

            disableNumericUpDownControls(this);
        }