Tri-State Checkboxes in WinForms TreeView

前端 未结 3 1712
离开以前
离开以前 2020-12-29 09:30

I have a TreeView that allows users to select certain elements of hierarchical data by checking or un-checking each item\'s checkbox. Currently I disable the box on nodes th

3条回答
  •  长情又很酷
    2020-12-29 10:10

    This code might help you if you are thinking of drawing the mixed checkbox

    class MixedCheckBox:Control
    {
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(0, 0), Bounds, 
                Text, Font, false, 
                System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal);
        }
    }
    

    This will render: enter image description here

    Good luck!

提交回复
热议问题