Solved

VB.net get X position of left of TreeView

Posted on 2012-04-03
7
296 Views
Last Modified: 2012-04-05
Hi. I am trying to gather the X position of the side of m TreeView so that
I can draw a vertical line from just to the right of the left border of the TreeView.
The variable intFrom_X_Axis in the following code gathers this but it isn't really working
Not sure why

    Private Sub TreeView_From_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TreeView_From.DragEnter
        'See if there is a TreeNode being dragged
        If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", _
            True) Then
            'TreeNode found allow move effect
            'e.Effect = DragDropEffects.Move
            e.Effect = DragDropEffects.All

        Else
            'No TreeNode found, prevent move
            e.Effect = DragDropEffects.None
            Exit Sub
        End If

        intFrom_X_Axis = Me.TreeView_From.Location.X + 20

        oFrom_Point = Me.TreeView_From.PointToClient(New Point(intFrom_X_Axis, e.Y))

    End Sub
0
Comment
Question by:murbro
  • 3
  • 2
  • 2
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37801715
What is the value of Location.X coming back before and after pointtoclient?
0
 

Author Comment

by:murbro
ID: 37801972
It comes back with a value of about 50 when e.X returms 1650
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37802039
That sounds right to me because you are translating it into treeview coordinates (x is 0 at left edge of treeview).
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37802109
What are you drawing on?  By that, I mean what control is the Graphics() associated with?
0
 

Author Comment

by:murbro
ID: 37812544
I am drawing on the TreeView

   Sub oDrawLine()

        Dim Gr As Graphics = Me.TreeView_From.CreateGraphics()
        ' Create pen.

        Dim orangePen As Pen        orangePen = New Pen(Color.DarkOrange, 2)
        'Dim point1 As New Point(10, 10)
        'Dim point2 As New Point(100, 500)
        Gr.DrawLine(orangePen, oFrom_Point, oTo_Point)

    End Sub
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37812883
Try:

        Dim ptX As Point = Me.TreeView_From.PointToScreen(New Point(0, 0))
        oFrom_Point = Me.TreeView_From.PointToClient(New Point(ptX.X, Cursor.Position.Y))
0
 

Author Closing Comment

by:murbro
ID: 37813049
Thanks very much
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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