Пример #1
0
        public static void GetDefaultControlAttributes(
            XmlNode rootNode, XmlDocument document, IXmlComponent xmlComponent, bool refLoad = false,
            XmlItemInterface.GetRealTimeArgsFunc argFunc = null, XmlItemInterface.GetComponentValueFunc comValueFunc = null)
        {
            xmlComponent.Interface = new XmlItemInterface(rootNode, document, xmlComponent);
            xmlComponent.Interface.GetRealTimeArgCallback        = argFunc;
            xmlComponent.Interface.GetComponentValueFuncCallBack = comValueFunc;

            if (refLoad == false)
            {
                String refPath = XmlGetter.Attribute(rootNode, "Ref");
                if (refPath.Length > 0)
                {
                    xmlComponent.LoadXml(refPath, true);
                }
            }

            Control targetControl = xmlComponent as Control;

            if (XmlGetter.Attribute(rootNode, "Margin").Length > 0)
            {
                targetControl.Margin = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Margin"));
            }
            if (XmlGetter.Attribute(rootNode, "Padding").Length > 0)
            {
                targetControl.Padding = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Padding"));
            }
            if (XmlGetter.Attribute(rootNode, "Enabled").Length > 0)
            {
                targetControl.Enabled = (XmlGetter.Attribute(rootNode, "Enabled").Equals("false") == false);
            }


            DockStyle dock = ValueParser.GetDockStyle(XmlGetter.Attribute(rootNode, "Dock"));

            switch (dock)
            {
            case DockStyle.Bottom:
            case DockStyle.Top:
            {
                String hgt = XmlGetter.Attribute(rootNode, "Height");
                if (hgt.Length != 0)
                {
                    targetControl.Height = int.Parse(hgt);
                }

                break;
            }

            case DockStyle.Left:
            case DockStyle.Right:
            {
                String wid = XmlGetter.Attribute(rootNode, "Width");
                if (wid.Length != 0)
                {
                    targetControl.Width = int.Parse(wid);
                }
                break;
            }

            case DockStyle.Fill:
                //필요없음..
                break;

            case DockStyle.None:
            {
                String hgt = XmlGetter.Attribute(rootNode, "Height");
                if (hgt.Length != 0)
                {
                    targetControl.Height = int.Parse(hgt);
                }
                String wid = XmlGetter.Attribute(rootNode, "Width");
                if (wid.Length != 0)
                {
                    targetControl.Width = int.Parse(wid);
                }
                String x        = XmlGetter.Attribute(rootNode, "X");
                Point  location = new Point();
                if (x.Length != 0)
                {
                    location.X = int.Parse(x);
                }
                String y = XmlGetter.Attribute(rootNode, "Y");
                if (y.Length != 0)
                {
                    location.Y = int.Parse(y);
                }
                targetControl.Location = location;
                break;
            }
            }
            targetControl.Dock = dock; //이 control이 붙을 parent에 docking하는 모드임..

            if (dock != DockStyle.Fill)
            {
                targetControl.Anchor = ValueParser.GetAnchorStyles(XmlGetter.Attribute(rootNode, "Anchor"));
            }


            string txt;

            txt = XmlGetter.Attribute(rootNode, "Name");
            if (txt.Length > 0)
            {
                targetControl.Name = txt;
            }

            txt = XmlGetter.Attribute(rootNode, "Text"); // attr.Value;
            if (txt.Length > 0)
            {
                targetControl.Text = txt;
            }


            string color = XmlGetter.Attribute(rootNode, "TextColor");

            if (color.Length > 0)
            {
                targetControl.ForeColor = ValueParser.StringToColor(color);
            }


            color = XmlGetter.Attribute(rootNode, "BackColor");
            if (color.Length == 0)
            {
                color = XmlGetter.Attribute(rootNode, "Background-Color");
            }
            try
            {
                if (color.Length > 0)
                {
                    targetControl.BackColor = ValueParser.StringToColor(color);
                }
            }
            catch (Exception e)
            {
                if (color.Length > 0)
                {
                    if (color.Equals("Transparent"))
                    {
                        if (targetControl.Parent != null)
                        {
                            targetControl.BackColor = targetControl.Parent.BackColor;
                        }
                        else
                        {
                            targetControl.BackColor = Color.FromKnownColor(KnownColor.Control);
                        }
                    }
                    else
                    {
                        throw new Exception("XmlControlHandler: 색 변환 중 에러.. color:" + color + "\r\n" + e.Message);
                    }
                }
            }

            LoadInterface(xmlComponent, rootNode, document);
        }