贤人必须成人,成人才能达己.

共同进步

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  49 随笔 :: 1 文章 :: 10 评论 :: 0 引用

公告

2008年9月10日 #

 private void InitGroupBox()
        {
            for (int k = 0; k < 16;k++ )
            {
                PictureBox pic = new PictureBox();
                int i = k % 4;
                int j = k / 4;
                pic.Name = k.ToString();
                pic.Top = 50 + j * 201;
                pic.Left = 50+i * 251;
                pic.Width = 250;
                pic.Height = 200;
                //pic.Visible = true;
                pic.Click  += new EventHandler(PictureBox_Click);
                pic.Paint += new PaintEventHandler(pictureBox_Paint);
                pic.BorderStyle = BorderStyle.FixedSingle;
                this.GroupPanel.Controls.Add(pic);
            }
        }
        private void PictureBox_Click(object sender, EventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            if (p == old) return;

            if (old != null)
            {
                old.Width -= 10;
                old.Height -= 10;
                old.Location = new Point(old.Location.X + 5, old.Location.Y + 5);
            }

            old = p;
            p.Width += 10;
            p.Height += 10;
            p.Location = new Point(p.Location.X - 5, p.Location.Y - 5);
            p.BringToFront(); 
          
        }
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            if (p == old)
            {
                Pen pp = new Pen(Color.Red);
                e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1);
            }
        } 

posted @ 2008-09-10 10:09 adi 阅读(202) 评论(0) 编辑

private void addChildren(string GroupName)
        {
            //首先判断是否选定组件中节点的位置
            if (this.groupTreeView.SelectedNode == null)
            {
                MessageBox.Show("请选择一个节点", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (GroupName != "")
                {
                    //创建一个节点对象,并初始化
                    TreeNode tmp;

                    tmp = new TreeNode(GroupName);
                    tmp.Name = "02";
                    tmp.Tag = "02";
                    //在treeview组件中加入兄弟节点
                    this.groupTreeView.SelectedNode.Nodes.Add(tmp);
                    this.groupTreeView.SelectedNode  = tmp;
                    this.groupTreeView.ExpandAll();
                }
                else
                {
                    MessageBox.Show("textbox组件必须填入节点名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            //treenode tnode = new treenode ( textbox1.text ) ;
        }

 //删除节点
        private void delNode()
        {
        
            //删除节点
            try
            {
                if (MessageBox.Show("确认删除该节点吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    this.groupTreeView.SelectedNode.Remove();

                }
                TreeView2Xml.Save(this.groupTreeView);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

 private void addparent (string GroupName)
       {
        //首先判断是否选定组件中节点的位置
            if ( this.groupTreeView .SelectedNode  == null )
            {
                MessageBox.Show  ( "请选择一个节点" , "提示信息" , MessageBoxButtons.OK , MessageBoxIcon.Information  ) ;
            }
            else
            {
                if (GroupName != "")
                {
                    //创建一个节点对象,并初始化
                    TreeNode tmp;

                    tmp = new TreeNode(GroupName);
                    tmp.Name = "01";
                    tmp.Tag = "01";
                    //在treeview组件中加入兄弟节点
                    this.groupTreeView.Nodes.Add (tmp);
                    this.groupTreeView .ExpandAll ();
                }
                else
                {
                    MessageBox.Show ("textbox组件必须填入节点名称!", "提示信息", MessageBoxButtons.OK , MessageBoxIcon.Information );
                    return ;
                }
            }
            //treenode tnode = new treenode ( textbox1.text ) ;
        }

posted @ 2008-09-10 10:07 adi 阅读(37) 评论(0) 编辑

class TreeView2Xml
    {
        private const string _SubFolder = "Xml";
        private const string _DecodeConfigName = "TreeView.xml";

        public static void Save(TreeView tv  )
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<Menu></Menu>");
                XmlNode root = doc.DocumentElement;
                doc.InsertBefore(doc.CreateXmlDeclaration("1.0", "utf-8", "yes"), root);
                TreeNode2Xml(tv.Nodes, root);
                doc.Save(CommonString.BuildFullPathName(_SubFolder, _DecodeConfigName));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static void TreeNode2Xml(TreeNodeCollection treeNodes, XmlNode xmlNode)
        {
            XmlDocument doc = xmlNode.OwnerDocument;
            foreach (TreeNode treeNode in treeNodes)
            {
                XmlNode element = doc.CreateNode("element", "Item", "");
                XmlAttribute attr = doc.CreateAttribute("Title");
                attr.Value = treeNode.Text;
                element.Attributes.Append(attr);
                attr = doc.CreateAttribute("id");
                attr.Value = treeNode.Name;
                element.Attributes.Append(attr);
                //element.AppendChild(doc.CreateCDataSection(treeNode.Tag.ToString()));
                xmlNode.AppendChild(element);

                if (treeNode.Nodes.Count > 0)
                {
                    TreeNode2Xml(treeNode.Nodes, element);
                }
            }
        }
        public static void Read(TreeView tv)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(CommonString.BuildFullPathName(_SubFolder, _DecodeConfigName));

                XmlNodeList xmlNodes = xmlDoc.DocumentElement.ChildNodes;

                tv.BeginUpdate();
                tv.Nodes.Clear();
                XmlNode2TreeNode(xmlNodes, tv.Nodes);
                tv.EndUpdate();
            }
            catch(Exception e)
            {
                throw e;
            }
        }
        public static void XmlNode2TreeNode(XmlNodeList xmlNode, TreeNodeCollection treeNode)
        {
            foreach (XmlNode var in xmlNode)
            {
                if (var.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                TreeNode newTreeNode = new TreeNode();
                newTreeNode.Text = var.Attributes["Title"].Value;
                newTreeNode.Name = var.Attributes["id"].Value;
                if (var.HasChildNodes)
                {
                    //if (var.ChildNodes[0].NodeType == XmlNodeType.CDATA)
                    //{
                    //    newTreeNode.Tag = var.ChildNodes[0].Value;
                    //}

                    XmlNode2TreeNode(var.ChildNodes, newTreeNode.Nodes);
                }
                treeNode.Add(newTreeNode);
            }
        }
    }
   

posted @ 2008-09-10 10:06 adi 阅读(40) 评论(0) 编辑