[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-18
4
Medium Priority
?
1,945 Views
Last Modified: 2012-05-12
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!
0
Comment
Question by:rustymoling
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 36988928
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
 

Author Comment

by:rustymoling
ID: 36992979
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
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 37027735
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
 

Author Closing Comment

by:rustymoling
ID: 37109574
Exactly what I needed, thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question