2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Customize the leaf nodes in treemapTo customize the TreeMap label font style and label text alignment, refer to the following steps. Step 1: Add ItemsSource and levels in order to populate the TreeMap. C# public partial class Form1 : Form { public Form1() { InitializeComponent(); TreeMap1.ItemsSource = data.PopulationDetails; TreeMapFlatLevel treeMapFlatLevel1 = new TreeMapFlatLevel(); treeMapFlatLevel1.GroupPath = "Continent"; TreeMap1.Levels.Add(treeMapFlatLevel1); TreeMap1.LeafItemSettings.LabelPath = "Country"; } }
Note: Refer to the sample for PopulationDetails provided for ItemsSource. Step 2: You can customize TreeMap label font style and label text alignment by using LeafItemDrawing event. Set e.cancel as true inside the event in order to redefine TreeMap label font style and text alignment. C# public partial class Form1 : Form { public Form1() { InitializeComponent(); TreeMap1.ItemsSource = data.PopulationDetails; TreeMap1.LeafItemDrawing += TreeMap1_LeafItemDrawing; } void TreeMap1_LeafItemDrawing(object sender, LeafItemDrawingEventArgs e) { e.Cancel = true; StringFormat drawFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; e.Graphics.FillRectangle(e.Color, e.RectSize); e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White), 1), e.RectSize); var font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Pixel, ((byte)(0))); e.Graphics.DrawString(e.Label, font, TreeMap1.LabelBrush, e.RectSize, drawFormat); } } C# public partial class Form1 : Form { public Form1() { InitializeComponent(); TreeMap1.ItemsSource = data.PopulationDetails; TreeMapFlatLevel treeMapFlatLevel1 = new TreeMapFlatLevel(); treeMapFlatLevel1.GroupPath = "Continent"; TreeMap1.Levels.Add(treeMapFlatLevel1); TreeMap1.LeafItemSettings.LabelPath = "Country"; TreeMap1.LeafItemDrawing += TreeMap1_LeafItemDrawing; } void TreeMap1_LeafItemDrawing(object sender, LeafItemDrawingEventArgs e) { e.Cancel = true; StringFormat drawFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; e.Graphics.FillRectangle(e.Color, e.RectSize); e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White), 1), e.RectSize); var font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Pixel, ((byte)(0))); e.Graphics.DrawString(e.Label, font, TreeMap1.LabelBrush, e.RectSize, drawFormat); } } The following screenshot illustrates the output. Figure 1: Treemap label with customized font style and label text alignment Sample: http://www.syncfusion.com/downloads/support/directtrac/138801/TreeMapSample-549397978.zip Reference link: https://help.syncfusion.com/windowsforms/treemap/customizing-leaf-nodes |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.