I have a tree view in my winform application.I have set its DrawMode property to OwnerDrawAll and used its drawnode event to customize tree nodes as I wanted to show highlighted text when user performs a search.Now, I want to improve it further by making its nodes look like the ones in the screenshot.They look like buttons.But how do I draw a rectangle which look like a button.
Here is my code to draw node.
private void trwFileExplorer_DrawNode(object sender, DrawTreeNodeEventArgs)
{
if (e.Node.IsSelected || trwFileExplorer_SelectedNodes.Contains(e.Node))
{
e.Graphics.FillRectangle(blueBrush, e.Bounds);
ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds, Color.White, blueBrush.Color);
e.Node.BackColor = blueBrush.Color;
e.Node.ForeColor = Color.White;
}
else
{
e.Node.ForeColor = Color.Black;
e.Node.BackColor = Color.Empty;
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
}
}
Without writing the code for you here are a few pointers that might help:
e.DrawDefault
to false
to completely take control of the drawing process. ▼
and ►
, and draw them as text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.