Solved

VB.net get X position of left of TreeView

Posted on 2012-04-03
7
297 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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