Exemplo n.º 1
0
        /// <summary>
        /// Loads the shape definition file.
        /// </summary>
        /// <param name="name">Name of shape.</param>
        /// <param name="data">Data that is passed to the shape object (not the form, the
        /// object that aids the Form).</param>
        public void LoadDefinition(string name, object data)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            _filename = FormConfigs.GetShapeFile(name);

            _definition = new XmlDocument(FormsNamespace.NamespaceManager.NameTable);
            _definition.Load(_filename);

            XmlElement attributesElem = (XmlElement)_definition.SelectSingleNode("/shape/attributes", FormsNamespace.NamespaceManager);

            if (attributesElem == null)
            {
                throw new ArgumentException("Missing attributes element.", "doc");
            }

            XmlNode formSize = (XmlElement)_definition.SelectSingleNode("/shape/properties/size", FormsNamespace.NamespaceManager);

            if (formSize != null)
            {
                if (formSize.Attributes["width"] != null && formSize.Attributes["width"].Value != null && formSize.Attributes["width"].Value.ToString().Length > 0)
                {
                    _formWidth = int.Parse(formSize.Attributes["width"].Value.ToString());
                }
                if (formSize.Attributes["height"] != null && formSize.Attributes["height"].Value != null && formSize.Attributes["height"].Value.ToString().Length > 0)
                {
                    _formHeight = int.Parse(formSize.Attributes["height"].Value.ToString());
                }
                ManageShapeSize();
            }
            string moniker = attributesElem.Attributes["moniker"].Value;

            object[] ctorArgs = new object[] { data, this, attributesElem };

            this.Tag = TypeFactory.Create(moniker, ctorArgs);
        }