Loading

TreeView的复选框隐藏 重新整理

CheckBoxes 为真

代码如下

using System.Runtime.InteropServices;

 

#region 树的复选框隐藏

        private const int TVIF_STATE = 0x8;
        private const int TVIS_STATEIMAGEMASK = 0xF000;
        private const int TV_FIRST = 0x1100;
        private const int TVM_SETITEM = TV_FIRST + 63;


        [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
        private struct TVITEM
        {
            public int mask;
            public IntPtr hItem;
            public int state;
            public int stateMask;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpszText;
            public int cchTextMax;
            public int iImage;
            public int iSelectedImage;
            public int cChildren;
            public IntPtr lParam;
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,ref TVITEM lParam);


        /// <summary>
        /// Hides the checkbox for the specified node on a TreeView control.
        /// 隐藏树的复选框
        /// <remarks>
        /// HideCheckBox(treeView1, node);
        /// </remarks>
        /// </summary>
        private void HideCheckBox(TreeView tvw, TreeNode node)
        {
            TVITEM tvi = new TVITEM();
            tvi.hItem = node.Handle;
            tvi.mask = TVIF_STATE;
            tvi.stateMask = TVIS_STATEIMAGEMASK;
            tvi.state = 0;
            SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
        }

        #endregion

 

使用方法

HideCheckBox(PerTreeView, rootTNode);

HideCheckBox(树对象, 节点对象);

节点对象前的复选框则隐藏了

 

 

posted @ 2012-06-26 09:59  jevan  阅读(750)  评论(0编辑  收藏  举报