我在TreeView中隐藏CheckBox有一个非常奇怪的问题。当TreeView位于Window中的第一个TabPage时,一切正常,但是当TreeView进入第二个TabPage时,第一个TreeNode总是有复选框。
我用来隐藏一些复选框的代码如下所示:
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;
public 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")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void TurnOff(TreeNode node) {
TVITEM tvi = new TVITEM();
tvi.hItem = node.Handle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi));
Marshal.StructureToPtr(tvi, lparam, false);
SendMessage(this.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
Marshal.FreeHGlobal(lparam);
}
如果有人知道此问题的解决方案,请分享。
答案 0 :(得分:0)