We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Detecting mouse click on a node''s image

Is there a way to detect if the image on the left side of the node''s text was clicked on? Thanks

3 Replies

MI Mike April 7, 2005 02:36 AM UTC

TreeNodeAdv that is.


AD Administrator Syncfusion Team April 8, 2005 09:48 PM UTC

Hi Mike, You could do so by handling the TreeViewAdv''s MouseUp event as shown below : private void treeViewAdv1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { TreeNodeAdv node = this.treeViewAdv1.SelectedNode; Point imgpt = new Point (node.TextAndImageBounds.X, node.TextAndImageBounds.Y); Size imgSize = new Size(this.imageList1.ImageSize.Width, this.imageList1.ImageSize.Height); Rectangle imgrec = new Rectangle(imgpt, imgSize); Point clickpt = new Point(e.X, e.Y); if (imgrec.Contains(clickpt)== true) { Console.WriteLine("Clicked on " + node.Text + "''s left image"); } } I have modified the TreeViewAdvImageOverlayingDemo sample accordingly and have attached it here. Please refer to it and let me know if this works for you. Regards, Guru Patwal Syncfusion, Inc.


AD Administrator Syncfusion Team August 2, 2005 06:24 PM UTC

Your sample does not work since the SelectedNode is not yet set to the node the user clicked on. The code below seems to work: Point clickpt = new Point(e.X, e.Y); TreeNodeAdv node = this.treeViewAdv1.PointToNode( clickpt ); string aText; aText = node.Text; Point imgpt = new Point (node.TextAndImageBounds.X, node.TextAndImageBounds.Y); Size imgSize = new Size(this.imageList1.ImageSize.Width, this.imageList1.ImageSize.Height); Rectangle imgrec = new Rectangle(imgpt, imgSize); if (imgrec.Contains(clickpt)== true) { Console.WriteLine("Clicked on " + node.Text + "''s left image"); }

Loader.
Up arrow icon