当前位置:编程学习 > C#/ASP.NET >>

winform中怎么把添加按钮的图片路径放入.xml文件中


添加图片后,会得到一个地址,怎么把操作把路径存进去,求代码。 winform c# --------------------编程问答-------------------- 先去弄清楚如何写xml(xmldocument) --------------------编程问答--------------------

 public class Config
    {
        private string _FileName;
        private XmlDocument _xmlDocument;
        /// <summary>
        /// 文件路径以及文件名
        /// </summary>
        public string FileName
        {
            get
            {
                return _FileName;
            }
            set
            {
                _FileName = value;
            }
        }

        #region 对xml文件操作

        // return :
        // true : the file exist and we open it 
        // false : the file doesn't exist and we create it 
        /// <summary>
        /// 判断是否存在,不存在则创建
        /// </summary>
        /// <returns></returns>
        public bool Open()
        {
            try
            {
                _xmlDocument.Load(_FileName);
            }
            catch (System.IO.FileNotFoundException)
            {
                //if file is not found, create a new xml file
                XmlTextWriter xmlWriter = new XmlTextWriter(_FileName, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("Root");
                //If WriteProcessingInstruction is used as above,
                //Do not use WriteEndElement() here
                //xmlWriter.WriteEndElement();
                //it will cause the <Root></Root> to be <Root />
                xmlWriter.Close();
                _xmlDocument.Load(_FileName);
                return false;
            }
            return true;
        }

        public Config(string strFileName)
        {
            FileName = strFileName;
            _xmlDocument = new XmlDocument();
            this.Open();
        }

        ~Config()
        {
            Save();
        }

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            _xmlDocument.Save(_FileName);
        }

        /// <summary>
        /// 根据节点名称获取值
        /// </summary>
        /// <param name="strName">节点名称</param>
        /// <returns>值内容</returns>
        public string Get(string strName)
        {
            XmlNode node = _xmlDocument.SelectSingleNode("Root").SelectSingleNode(strName);
            if (node == null)
            {
                return "nonexist";
            }
            else
            {
                return node.InnerText;
            }
        }

        /// <summary>
        /// 创建新节点
        /// </summary>
        /// <param name="strName">节点名称</param>
        /// <param name="strValue">节点值</param>
        public void Set(string strName, string strValue)
        {
            XmlNode root = _xmlDocument.SelectSingleNode("Root");
            XmlNode node = root.SelectSingleNode(strName);

            if (node != null)
            {
                node.InnerText = strValue;
            }
            else
            {
                XmlElement elem = _xmlDocument.CreateElement(strName);
                elem.InnerText = strValue;
                root.AppendChild(elem);
            }
        }
--------------------编程问答-------------------- 我也有相似的问题,winform 怎么样获取已经绑定控件的图片路径?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,