public void TestBadLocation ()
		{
			TreeViewHitTestInfo t = new TreeViewHitTestInfo (null, (TreeViewHitTestLocations) (-1));

			Assert.AreEqual (t.Node, null, "bad-loc-1");
			Assert.AreEqual ((int) t.Location, -1, "bad-loc-2");
		}
Exemple #2
0
        private void treeView1_MouseMove(object sender, MouseEventArgs e)
        {
            pt        = e.Location;
            treeNode1 = treeView1.GetNodeAt(e.Location);



            if (treeNode1 == null || treeNode1.Text == "")
            {
                treeView1.Cursor = Cursors.Arrow;
                return;
            }

            //改变光标成小手
            TreeViewHitTestInfo info = treeView1.HitTest(e.Location);

            if (info.Location == TreeViewHitTestLocations.Image || info.Location == TreeViewHitTestLocations.Label)
            {
                treeView1.Cursor = Win32API.Hand;
            }
            else
            {
                treeView1.Cursor = Cursors.Arrow;
            }
        }
 protected override void OnMouseDoubleClick(MouseEventArgs e)
 {
     System.Windows.Forms.TreeViewHitTestInfo info = this.HitTest(e.X, e.Y);
     if (info.Node != null && info.Location.ToString() == "StateImage")
     {
         return;
         //OnCustomCheck(info.Node, System.Windows.Forms.TreeViewAction.ByMouse);
     }
     base.OnMouseDoubleClick(e);
 }
Exemple #4
0
        private void OnDragOver(Object sender, DragEventArgs e)
        {
            Point point             = this.PointToClient(new Point(e.X, e.Y));
            TreeViewHitTestInfo hit = this.HitTest(point);

            if (hit.Node != null)
            {
                this.SelectedNode = hit.Node;
            }
        }
 private void tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     // is the click on the checkbox?  If not, discard it
     System.Windows.Forms.TreeViewHitTestInfo info = this.tree.HitTest(e.X, e.Y);
     if (info == null || info.Location != System.Windows.Forms.TreeViewHitTestLocations.StateImage)
     {
         return;
     }
     ((TreeNodeTri)e.Node).Click();
 }
Exemple #6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            System.Windows.Forms.TreeViewHitTestInfo info = this.HitTest(e.X, e.Y);
            if (info.Node != null && info.Location.ToString() == "StateImage")
            {
                _isCheckBoxClicked = true;
            }

            //
            //base.OnMouseDown(e);
        }
Exemple #7
0
        // <summary>
        // Called when node is clicked by the mouse.  Does nothing unless the image was clicked
        // Invokes OnAfterCheck to do the real work
        // </summary>
        protected override void OnNodeMouseClick(System.Windows.Forms.TreeNodeMouseClickEventArgs e)
        {
            base.OnNodeMouseClick(e);

            // is the click on the checkbox?  If not, discard it
            System.Windows.Forms.TreeViewHitTestInfo info = HitTest(e.X, e.Y);
            if (info == null || info.Location != System.Windows.Forms.TreeViewHitTestLocations.StateImage)
            {
                return;
            }

            // toggle the node's checked status.  This will then fire OnAfterCheck
            System.Windows.Forms.TreeNode tn = e.Node;
            tn.Checked = !tn.Checked;
        }
		public void TestCtor ()
		{
			TreeViewHitTestInfo t = new TreeViewHitTestInfo (null, TreeViewHitTestLocations.None);

			Assert.AreEqual (t.Node, null, "null-1");
			Assert.AreEqual (t.Location, TreeViewHitTestLocations.None, "null-2");

			t = new TreeViewHitTestInfo (null, TreeViewHitTestLocations.Image);

			Assert.AreEqual (t.Node, null, "loc-1");
			Assert.AreEqual (t.Location, TreeViewHitTestLocations.Image, "loc-2");

			TreeNode tn = new TreeNode ("test");
			t = new TreeViewHitTestInfo (tn, TreeViewHitTestLocations.PlusMinus);

			Assert.AreEqual (t.Node, tn, "node-1");
			Assert.AreEqual (t.Location, TreeViewHitTestLocations.PlusMinus);
		}
Exemple #9
0
        //TreeViewAction m_action = TreeViewAction.Unknown;
        protected void OnNodeMouseClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
        {
            //base.OnNodeMouseClick(e);

            // is the click on the checkbox?  If not, discard it
            System.Windows.Forms.TreeViewHitTestInfo info = m_tree.HitTest(e.X, e.Y);
            if (info == null || info.Location != System.Windows.Forms.TreeViewHitTestLocations.StateImage)
            {
                return;
            }

            // toggle the node's checked status.  This will then fire OnAfterCheck
            System.Windows.Forms.TreeNode tn = e.Node;
            //m_action = TreeViewAction.ByMouse;
            var bChk = Check(tn);

            Check(tn, !bChk);
            Tree_AfterCheck(this, new TreeViewEventArgs(e.Node, TreeViewAction.ByMouse));
            //m_action = TreeViewAction.Unknown;
        }
Exemple #10
0
 protected override void OnMouseClick(MouseEventArgs e)
 {
     if (_isCheckBoxClicked)
     {
         System.Windows.Forms.TreeViewHitTestInfo info = this.HitTest(e.X, e.Y);
         if (info.Node != null)
         {
             if (info.Node != null && info.Location.ToString() == "StateImage")
             {
                 _isCheckBoxClicked = true;
                 CheckBoxClicked(info.Node as TriStateTreeNode);
             }
             else
             {
                 _isCheckBoxClicked = false;
             }
         }
         _isCheckBoxClicked = false;
     }
     //base.OnMouseClick(e);
 }
Exemple #11
0
    // <summary>
    // Called when node is clicked by the mouse.  Does nothing unless the image was clicked
    // Invokes OnAfterCheck to do the real work
    // </summary>
    protected override async void OnNodeMouseClick(System.Windows.Forms.TreeNodeMouseClickEventArgs e)
    {
        base.OnNodeMouseClick(e);

        if (e.Button == MouseButtons.Right)
        {
            System.Windows.Forms.TreeViewHitTestInfo info = HitTest(e.X, e.Y);
            if (info.Location == TreeViewHitTestLocations.Label || info.Location == TreeViewHitTestLocations.RightOfLabel)
            {
                this.SelectedNode = e.Node;
                return;
            }
        }

        // toggle the node's checked status.  This will then fire OnAfterCheck
        System.Windows.Forms.TreeNode tn = e.Node;
        if (tn.Tag.ToString() != "Folder")
        {
            tn.Checked = !tn.Checked;
            await UpdateCounters();
        }
        else
        {
            // is the click on the checkbox?  If not, discard it
            System.Windows.Forms.TreeViewHitTestInfo info = HitTest(e.X, e.Y);
            if (info == null || info.Location != System.Windows.Forms.TreeViewHitTestLocations.StateImage)
            {
                return;
            }
            else
            {
                tn.Checked = !tn.Checked;
                await UpdateCounters();
            }
        }
    }
Exemple #12
0
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            //treeView1.BeginUpdate();
            #region 1     选中的节点背景=========================================
            Rectangle nodeRect = new Rectangle(1,
                                               e.Bounds.Top,
                                               e.Bounds.Width - 3,
                                               e.Bounds.Height - 1);

            if (e.Node.IsSelected)
            {
                //TreeView有焦点的时候 画选中的节点
                if (treeView1.Focused || textBox1.Visible)
                {
                    e.Graphics.FillRectangle(brush1, nodeRect);
                    e.Graphics.DrawRectangle(pen1, nodeRect);

                    /*测试 画聚焦的边框*/
                    //ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds, Color.Black, SystemColors.Highlight);
                }
                /*TreeView失去焦点的时候 */
                else
                {
                    e.Graphics.FillRectangle(brush2, nodeRect);
                    e.Graphics.DrawRectangle(pen2, nodeRect);
                }
            }
            else if ((e.State & TreeNodeStates.Hot) != 0 && e.Node.Text != "")//|| currentMouseMoveNode == e.Node)
            {
                e.Graphics.FillRectangle(brush3, nodeRect);
                e.Graphics.DrawRectangle(pen3, nodeRect);
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(treeView1.BackColor), e.Bounds);
            }
            #endregion

            #region 2     +-号绘制=========================================
            Rectangle plusRect = new Rectangle(e.Node.Bounds.Left - 32, nodeRect.Top + 7, 9, 9); // +-号的大小 是9 * 9
            if (e.Node.IsExpanded && e.Node.Nodes.Count > 0)
            {
                //treeView1.Refresh();
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    e.Graphics.DrawImage(minusPictureBox1.Image, plusRect);
                }
            }
            else if (e.Node.IsExpanded == false && e.Node.Nodes.Count > 0)
            {
                //treeView1.Refresh();
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    e.Graphics.DrawImage(plusPictureBox1.Image, plusRect);
                }
            }

            TreeViewHitTestInfo info = treeView1.HitTest(pt);
            if (treeNode1 != null && info.Location == TreeViewHitTestLocations.PlusMinus && treeNode1 == e.Node)
            {
                if (treeNode1.IsExpanded && treeNode1.Nodes.Count > 0)
                {
                    e.Graphics.DrawImage(minusPictureBox2.Image, plusRect);
                }
                else if (treeNode1.IsExpanded == false && treeNode1.Nodes.Count > 0)
                {
                    e.Graphics.DrawImage(plusPictureBox2.Image, plusRect);
                }
            }


            /*测试用 画出+-号出现的矩形*/
            //if (e.Node.Nodes.Count > 0)
            //    e.Graphics.DrawRectangle(new Pen(Color.Red), plusRect);
            #endregion

            #region 3     画节点文本=========================================
            Rectangle nodeTextRect = new Rectangle(
                e.Node.Bounds.Left,
                e.Node.Bounds.Top + 2,
                e.Node.Bounds.Width + 2,
                e.Node.Bounds.Height
                );
            nodeTextRect.Width  += 4;
            nodeTextRect.Height -= 4;

            e.Graphics.DrawString(e.Node.Text,
                                  e.Node.TreeView.Font,
                                  new SolidBrush(treeView1.ForeColor),
                                  nodeTextRect);


            ////画子节点上文件的个数 (111)
            if (e.Node.Text != "" &&
                Directory.Exists(rootpath + "\\" + e.Node.FullPath))
            {
                string[] filelist = Directory.GetFiles(rootpath + "\\" + e.Node.FullPath, "*.htm");
                nodeTextRect.Width  += 4;
                nodeTextRect.Height -= 4;
                //画子节点个数 (111)
                if (e.Node.Text != "" && filelist.Length > 0)
                {
                    e.Graphics.DrawString(string.Format("({0})", filelist.Length),
                                          new Font("Arial", 8),
                                          Brushes.Gray,
                                          nodeTextRect.Right - 4,
                                          nodeTextRect.Top + 2);
                }
            }

            Rectangle r = e.Node.Bounds;
            r.Height -= 2;
            ///*测试用,画文字出现的矩形*/
            //if (e.Node.Text != "")
            //    e.Graphics.DrawRectangle(new Pen(Color.Blue), r);
            #endregion

            #region 4   画IImageList 中的图标===================================================================

            int currt_X = e.Node.Bounds.X;
            if (treeView1.ImageList != null && treeView1.ImageList.Images.Count > 0)
            {
                //图标大小16*16
                Rectangle imagebox = new Rectangle(
                    e.Node.Bounds.X - 3 - 16,
                    e.Node.Bounds.Y + 3,
                    16,  //IMAGELIST IMAGE WIDTH
                    16); //HEIGHT


                int    index    = e.Node.ImageIndex;
                string imagekey = e.Node.ImageKey;
                if (imagekey != "" && treeView1.ImageList.Images.ContainsKey(imagekey))
                {
                    e.Graphics.DrawImage(treeView1.ImageList.Images[imagekey], imagebox);
                }
                else
                {
                    if (e.Node.ImageIndex < 0)
                    {
                        index = 0;
                    }
                    else if (index > treeView1.ImageList.Images.Count - 1)
                    {
                        index = 0;
                    }
                    e.Graphics.DrawImage(treeView1.ImageList.Images[index], imagebox);
                }
                currt_X -= 19;

                /*测试 画IMAGELIST的矩形*/
                //if (e.Node.ImageIndex > 0)
                //    e.Graphics.DrawRectangle(new Pen(Color.Black, 1), imagebox);
            }
            #endregion

            #region 测试 画所有的边框
            //nodeRect = new Rectangle(1,
            //             e.Bounds.Top + 1,
            //             e.Bounds.Width - 3,
            //             e.Bounds.Height - 2);
            //e.Graphics.DrawRectangle(new Pen(Color.Gray), nodeRect);
            #endregion
            //treeView1.EndUpdate();
        }