borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (icons in menus)Next Topic (How to ....in Date/Time?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Line Control
Poster Message
kirants
Level: Guest


icon Line Control  Archived to Disk

There is no move method for the Line control . So How to move line control however the line is drawn like
  --------------

   or

   |              /       *    
   |             /         *  
   | or         /    or     *    
   |           /             *    
   |          /               *      

The drawn line must be able to drag and drop (ie., moved).  

02-05-2002 at 11:44 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Line Control  Archived to Disk

It uses (x1, y1)-(x2, y2) to move it, you actually have to modify the starting and ending coords. (it follows a standard grid, x is left-right, y is up-down)

For example:
(assuming there's a line control on the form:

Private Sub Form_Click()
    Line1.X1 = 10
    Line1.X2 = 500
    Line1.Y1 = 400
    Line1.Y2 = 400
End Sub

Private Sub Form_Load()
    Line1.X1 = 10
    Line1.X2 = 500
    Line1.Y1 = 100
    Line1.Y2 = 100
End Sub


if you just draw a line (me.line, not a line control), then you'll have to draw a line over the old one with the same color as the background (me.forecolor=me.backcolor) then draw a new line where needed.

02-05-2002 at 04:38 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Line Control  Archived to Disk

The code to move the line is the same as the code to move a control, with the exception that you use the (X,Y) instead of (left,top) and you have to keep track of the line's "width" and "height".



Option Explicit

Private Type tCoords
    X As Single
    Y As Single
End Type

Private fMoving As Boolean
Private tMoving As tCoords

Private Sub Form_Load()
    With tMoving
        .X = -1
        .Y = -1
    End With
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim X2 As Long
    Dim Y2 As Long
    If Not fMoving And Button = 1 Then
        If X >= (Line1.X1) And X <= (Line1.X2) Then
        ' -20 and +20 just to give more of a "grip"
            If Y >= (Line1.Y1) - 20 And Y <= (Line1.Y2) + 20 Then
                fMoving = True
            End If
        End If
    ElseIf Button <> 1 Then
        fMoving = False
    End If

    If fMoving Then
    ' If values = -1 then we haven't stored the starup X,Y
        If tMoving.X = -1 And tMoving.Y = -1 Then
            tMoving.X = X
            tMoving.Y = Y
        Else
        ' Move the shape the current position - the difference of the mouse move
        ' if last X-current X = positive, then move to left (current left - x)
        ' if last X-current X = negative, then move to right (current left - -x = left + x)
            X2 = Line1.X2 - Line1.X1
            Y2 = Line1.Y2 - Line1.Y1
            Line1.X1 = Line1.X1 - (tMoving.X - X)
            Line1.Y1 = Line1.Y1 - (tMoving.Y - Y)
            Line1.X2 = Line1.X1 + X2
            Line1.Y2 = Line1.Y1 + Y2
            tMoving.X = X
            tMoving.Y = Y
        End If
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' We're not moving, reset the variables
    fMoving = False
    With tMoving
        .X = -1
        .Y = -1
    End With
End Sub

03-05-2002 at 04:26 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Line Control
Previous Topic (icons in menus)Next Topic (How to ....in Date/Time?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder