Jump to content


Photo

How to limit only vertical or horizontal resize but not diagonal


1 reply to this topic

#1 Athanasios Gardos

Athanasios Gardos

    Administrator

  • Admin
  • 359 posts
  • Gender:Male

Posted 17 March 2016 - 12:04 PM

Private Sub cAvax1_SelectRegionStretch(StretchHandles() As Long, xOldMin As Single, yOldMin As Single, xOldMax As Single, yOldMax As Single, xNewMin As Single, yNewMin As Single, xNewMax As Single, yNewMax As Single, fCancel As Boolean)
    Dim dxOld As Single
    Dim dyOld As Single
    Dim dxNew As Single
    Dim dyNew As Single
    dxOld = Abs(xOldMax - xOldMin)
    dyOld = Abs(yOldMax - yOldMin)
    dxNew = Abs(xNewMax - xNewMin)
    dyNew = Abs(yNewMax - yNewMin)
    If Not (AlmostTheSame(dxOld, dxNew) = True And AlmostTheSame(dyOld, dyNew) = True) Then
        If Not ((xNewMin <> xOldMin And yNewMin <> yOldMin) Or _
           (xNewMax <> xOldMax And yNewMax <> yOldMax) Or _
           (xNewMin <> xOldMin And yNewMax <> yOldMax) Or _
           (xNewMax <> xOldMax And yNewMin <> yOldMin)) Then
           fCancel = True
        End If
    End If
End Sub

Private Function AlmostTheSame(a As Single, b As Single) As Boolean
    If Abs(a - b) < 0.0001 Then AlmostTheSame = True
End Function

Private Sub Form_Load()
    Call cAvax1.StartAvax
    cAvax1.Add_Line 0, 0, 0, 10, 10, 0
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call cAvax1.EndAvax
End Sub


Athanasios Gardos
Avax-Software.com

#2 Athanasios Gardos

Athanasios Gardos

    Administrator

  • Admin
  • 359 posts
  • Gender:Male

Posted 19 March 2016 - 03:44 PM

When we have a vertical rectangle and we want to control that only the Y’s(height) can be changed.

(When it is a horizontal rectangle, the X’s (width)can be changed.)

We can use the following code:

Private Sub cAvax1_SelectRegionStretch(StretchHandles() As Long, xOldMin As Single, yOldMin As Single, xOldMax As Single, yOldMax As Single, xNewMin As Single, yNewMin As Single, xNewMax As Single, yNewMax As Single, fCancel As Boolean)
    Dim lCnt As Long, lMax As Long
    Dim dxOld As Single
    Dim dyOld As Single
    Dim dxNew As Single
    Dim dyNew As Single
    dxOld = Abs(xOldMax - xOldMin)
    dyOld = Abs(yOldMax - yOldMin)
    dxNew = Abs(xNewMax - xNewMin)
    dyNew = Abs(yNewMax - yNewMin)
    lMax = UBound(StretchHandles())
    If Not (AlmostTheSame(dxOld, dxNew) = True And AlmostTheSame(dyOld, dyNew) = True) Then
        For lCnt = 1 To lMax
            Select Case LCase$(cAvax1.GetHandleKey(StretchHandles(lCnt)))
                Case "vertical rectangle"
                    If Not ((yNewMin <> yOldMin) Or _
                       (yNewMax <> yOldMax) Or _
                       (yNewMax <> yOldMax) Or _
                       (yNewMin <> yOldMin)) Then
                       fCancel = True
                    End If
                Case "horizontal rectangle"
                    If Not ((xNewMin <> xOldMin) Or _
                       (xNewMax <> xOldMax) Or _
                       (xNewMin <> xOldMin) Or _
                       (xNewMax <> xOldMax)) Then
                       fCancel = True
                    End If
                Case Else
                    fCancel = True
                    Exit Sub
            End Select
        Next lCnt
    End If
End Sub

Private Function AlmostTheSame(a As Single, b As Single) As Boolean
    If Abs(a - b) < 0.0001 Then AlmostTheSame = True
End Function

Private Sub Form_Load()
    Dim h() As Long
    Call cAvax1.StartAvax
    ReDim h(3) As Long
    h(1) = cAvax1.Add_Rectangle(0, 0, 100, 50)
    Call cAvax1.SetHandleKey(h(1), "horizontal rectangle")
    h(2) = cAvax1.Add_Rectangle(120, 0, 50, 100)
    Call cAvax1.SetHandleKey(h(2), "vertical rectangle")
    h(3) = cAvax1.Add_Rectangle(180, 0, 50, 100)
    Call cAvax1.SetHandleKey(h(3), "vertical rectangle")
    cAvax1.Command = AutoLimits_c
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call cAvax1.EndAvax
End Sub


Athanasios Gardos
Avax-Software.com



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users