简体   繁体   中英

How to implement a button styled tree view in c# winform application?

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:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM