Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Rotate Line controls This example shows how to rotate Line controls in Visual Basic 6. Line control Controls, Multimedia

The program uses these equations to calculate the position of a point on a circle.

```    X = R * Cos(theta)
Y = R * Sin(theta)```

When the program's Timer fires, the code rotates two Line controls. For the first, it makes the Line's second end point rotate around its first end point.

The program rotates the second Line's end points around the line's center.

```Private Const D_THETA = 3.14159265 / 12
Private Theta As Single
Private R1 As Single
Private R2 As Single
Private Cx1 As Single
Private Cy1 As Single
Private Cx2 As Single
Private Cy2 As Single

Dim dx As Single
Dim dy As Single

dx = Line1.X2 - Line1.X1
dy = Line1.Y2 - Line1.Y1
R1 = Sqr(dx * dx + dy * dy)
Cx1 = Line1.X1
Cy1 = Line1.Y1

dx = Line2.X2 - Line2.X1
dy = Line2.Y2 - Line2.Y1
R2 = Sqr(dx * dx + dy * dy) / 2
Cx2 = (Line2.X1 + Line2.X2) / 2
Cy2 = (Line2.Y1 + Line2.Y2) / 2
End Sub

Private Sub Timer1_Timer()
Theta = Theta + D_THETA

Line1.X2 = Cx1 + Cos(Theta) * R1
Line1.Y2 = Cy1 + Sin(Theta) * R1

Line2.X1 = Cx2 + Cos(Theta) * R2
Line2.Y1 = Cy2 + Sin(Theta) * R2
Line2.X2 = Cx2 - Cos(Theta) * R2
Line2.Y2 = Cy2 - Sin(Theta) * R2
End Sub```