(C#) How can I find the screen location of a treeview item?

The location changes, because the treeview is scrolling. I am drawing an additional bitmap next to a highlighted item. If I could find the coordinates of a given item, I'd have no problem drawing that bitmap in the required location.

Thanks anyone who can help!
rustymolingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
If you are using winforms, check mouse move event:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.mousemove(v=VS.85).aspx

private void MouseMoveHandler(object sender, MouseEventArgs e)
{
    // Get the x and y coordinates of the mouse pointer.
    Point position = e.GetPosition(this);
    double pX = position.X;
    double pY = position.Y;

    // Asuming your treeview width is 100 and scrollbar width is 10.
    position.Y = 100-2*10;//position.Y;
 // Convert to a point in the TreeView's coordinate system. (these are the coordinates you need)
            position  = treeview1.PointToClient(position );
            // Get the node underneath the mouse if required to check if piicking the right node.
            TreeNode node = treeview1.GetNodeAt(pt);
}

0
rustymolingAuthor Commented:
Well, you are getting coordinates from the event args of a Mouse Move event - and I don't want to use that. Things are changing in my tree view as a result of a background process. And there are more things in the treeview than can fit on the screen, so the scrollbar is active. And users minimize and maximize this window, which sometimes strangely alters what list of items is visible on the screen.

To me, it seems simplest to locate which treenode is the currently relevant one, and get hold of its current screen position, but I haven't had any luck with that - I don't know which properties it might have to help me with that, and I don't know how to cast it to anything that might have the properties I'm looking for.
0
Miguel OzSoftware EngineerCommented:
Use bounds property, The node coordinates are relative to the upper-left corner of the TreeView control.
http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.bounds.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rustymolingAuthor Commented:
Exactly what I needed, thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.