How to implement the icon click event for WinForms TreeView

2 Answers 18 Views
Treeview
yw
Top achievements
Rank 2
Iron
Iron
yw asked on 22 Aug 2025, 02:18 AM

WinForms TreeView displays icons and text. How to obtain the Rectangle of the icon area, or how to implement the click event of the icon. Through the method in https://www.telerik.com/forums/hovering-over-node-image: 
TreeNodeImageElement imageElement = radTreeView1.ElementTree.GetElementAtPoint(e.Location) as TreeNodeImageElement;
The obtained structure is null, and the version is 2025.

thaks

2 Answers, 1 is accepted

Sort by
0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 25 Aug 2025, 10:13 AM

Hello,

If I understand correctly, you have applied images to the nodes in RadTreeView and you need to handle when the user clicks over the image element, am I right? You are referring to quite an old forum post that might have changed over the years.

To distinguish when the user clicks on the TreeNodeImageElement, you should first specify the ShouldHandleMouseInput property to true. Then, handle TreeNodeImageElement.MouseDown event. Refer to the following example:

 private void RadTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
 {
     TreeNodeImageElement image = e.NodeElement.ImageElement; 
     if (image != null)
     {
         image.ShouldHandleMouseInput = true;
         image.MouseDown += ImageElement_MouseDown;
     }
 }

 private void ImageElement_MouseDown(object sender, MouseEventArgs e)
 {
     // TODO: Add your custom logic here 
 }

I hope this helps. If you have any other questions, please let me know.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
yw
Top achievements
Rank 2
Iron
Iron
answered on 25 Aug 2025, 02:34 PM
thanks!
Tags
Treeview
Asked by
yw
Top achievements
Rank 2
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
yw
Top achievements
Rank 2
Iron
Iron
Share this question
or