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.
Unfortunately, activation email could not send to your email. Please try again.

Detecting mouse click on a node''s image

Thread ID:

Created:

Updated:

Platform:

Replies:

27159 Apr 6,2005 07:06 PM Aug 2,2005 02:24 PM Windows Forms 3
loading
Tags: Tools
Mike
Asked On April 6, 2005 07:06 PM

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

Mike
Replied On April 6, 2005 10:36 PM

TreeNodeAdv that is.

Administrator [Syncfusion]
Replied On April 8, 2005 05:48 PM

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.

Administrator [Syncfusion]
Replied On August 2, 2005 02:24 PM

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"); }

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;