It was found that TreeNode had no relevant attributes, and the CheckBox in the TreeView was basically out of control, so I went online for help and basically talked nonsense. Some heroes couldn't even tell WinForm and WebForm.
Some people say that the font color of the node is set to gray, and then:
| The code is as follows: |
Copy code |
|
Private void mytreeviewinclubeforecheck (object sender, TreeViewCancelEventArgs e)
{
If (e. Node. ForeColor = Color. Gray)
E. Cancel
} |
In this way, the requirements can be basically met, but there are two problems,
1. Check boxes that you want to disable are still in the non-disabled status. They are useless only when you click the check box and are visually confused.
2. When double-clicking, mytreeviewdomainbeforecheck becomes invalid. That is, you can select or deselect the CheckBox.
So far, the network query solution has completely failed, so I am wondering if this is really difficult? Why can't anyone give a question? Are programmers like this?
So I thought of rewriting the TreeView, and my idea was to draw the Node when TreeView, if e. Node. ForeColor = color. Gray, draw a disabled ChceckBox to overwrite the current CheckBox, http://www.111cn.net
The code is as follows:
| The code is as follows: |
Copy code |
|
Public partial class MyTreeView: TreeView
{
Private Brush B = null; // Node font color
Private Point p; // specifies the position of the CheckBox.
Public MyTreeView ()
{
This. DrawMode = TreeViewDrawMode. OwnerDrawText; // draw the text by yourself.
}
Protected override void OnDrawNode (DrawTreeNodeEventArgs e)
{
B = Brushes. Black; // The default font is Black.
If (e. Node. ForeColor = Color. Gray)
{
P = e. Bounds. Location; // Obtain the node Location
P. X = p. X-12; // overwrite the position of the default CheckBox.
CheckBoxRenderer. DrawCheckBox (e. Graphics, p, CheckBoxState. CheckedDisabled); // draw a disabled CheckBox
B = Brushes. Gray; // The font of the current node is Gray.
}
If (e. State & TreeNodeStates. Focused )! = 0)
B = Brushes. White; // when you click a node, the font color is White.
E. Graphics. DrawString (e. Node. Text, this. Font, B, e. Bounds. Location); // draw Text
}
}
|
There are many states in CheckBoxState. The CheckBoxState. MixedHot three-state dialog box is shown in the following figure.