溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C# Winform TreeView CheckBox 部分顯示(代碼)

發布時間:2020-07-25 18:02:14 來源:網絡 閱讀:2448 作者:lqtc0722 欄目:編程語言
public partial class Form1Form
{
private const intTVIF_STATE = 0x8;
private const intTVIS_STATEIMAGEMASK = 0xF000;
private const intTV_FIRST = 0x1100;
private const intTVM_SETITEM = TV_FIRST + 63;
 
public Form1()
{
InitializeComponent();
this.treeView1.CheckBoxes = true;
this.treeView1.ShowLines = false;
this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView_DrawNode);
for(int i = 0; i < 10;++i)
{
this.treeView1.Nodes.Add(string.Format("First level {0}", i));
for(int j = 0; j < 5;j++)
{
this.treeView1.Nodes[i].Nodes.Add(string.Format("Second level {0}", j));
for(int k = 0; k < 5;k++)
{
this.treeView1.Nodes[i].Nodes[j].Nodes.Add(string.Format("Thirdlevel {0}", k));
}
}
}
this.treeView1.ExpandAll();
}
Private void treeView_DrawNode(object sender, DrawTreeNodeEventArgse)
{
if(e.Node.Level == 1)
HideCheckBox(this.treeView1,e.Node);
e.DrawDefault = true;
}
[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. 
///</summary>
Private void HideCheckBox(TreeView tvw, TreeNodenode)
{
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);
}
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女