Trying to extend TreeView \ TreeNode class in .NET 2.0 but need some
advice.
In the above code I'm able to draw the TreeNodeEx text in any font \
color \ size I want and add an image. However, I'd also like to add an
checkbox for each TreeNodeEx added to TreeViewEx but I have no clue
howto draw it in the Draw method (or if thats the approperiate place to
do it). Using ControlPaint.DrawCheckbox is not really an option as far
as I can see (does not contain any functionality only an drawing - cant
check \ uncheck it).
Appreciate any help.
public class TreeViewEx : System.Windows.Forms.TreeView
{
ImageList ImgList;
public TreeViewEx()
{
ImgList = new ImageList();
ImgList.TransparentColor = Color.FromArgb(255, 0, 255);
ImgList.Images.Add(Bitmap.FromFile("C:\\Delete.bmp "));
this.DrawMode = TreeViewDrawMode.OwnerDrawAll;
this.DrawNode += new DrawTreeNodeEventHandler(Draw);
}
public void Draw(Object sender, DrawTreeNodeEventArgs e)
{
TreeNodeEx Node = (TreeNodeEx)e.Node;
Font f;
if (Node.bEnabled)
{
f = new Font("Arial", 12, FontStyle.Italic,
GraphicsUnit.Pixel);
}
else
{
f = new Font("Arial", 12, FontStyle.Regular,
GraphicsUnit.Pixel);
}
e.Graphics.DrawString("Node", f, new SolidBrush(Color.Red),
e.Bounds.Left, e.Bounds.Top);
e.Graphics.DrawImage(ImgList.Images[0], e.Bounds.Left + 50,
e.Bounds.Top);
Node.chkBox.Location = new System.Drawing.Point(e.Bounds.X,
e.Bounds.Y);
Node.chkBox.Show();
}
}
public class TreeNodeEx : System.Windows.Forms.TreeNode
{
public TreeNodeEx(bool enabled) : base()
{
bEnabled = enabled;
chkBox = new CheckBox();
chkBox.Size = new System.Drawing.Size(50, 50);
chkBox.Name = "_test_";
chkBox.Text = "_test_";
chkBox.Visible = true;
chkBox.Enabled = true;
}
public bool bEnabled = false;
public CheckBox chkBox = null;
}