Results 1 to 5 of 5

Thread: Super cool Form Effect!

  1. #1

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Super cool Form Effect!

    Drag several controls(any control, labels, command buttons, textboxes,
    picture boxes, etc) onto the form, then paste this code onto your form.
    You'll see some uber cool effects!
    VB Code:
    1. '(C) Copyright jian2587 2005. Use freely but give credit! :)
    2. Private Sub Form_Load()
    3. RotateControls
    4. End Sub
    5.  
    6. Private Sub RotateControls(Optional ByVal msTime As Single = 3)
    7. Dim lLeft() As Long
    8. Dim lTop() As Long
    9. Dim sngDegree() As Single
    10. Dim sngDistance() As Long
    11. Dim sngStepX() As Single
    12. Dim sngStepY() As Single
    13. Dim CtrlCount As Long
    14. Dim i As Long
    15. Dim Ctrl As Control
    16. Dim cX As Long
    17. Dim cY As Long
    18. Dim Pi As Double
    19. Dim DegRad As Single
    20. Dim RadDeg As Single
    21. Dim t As Single
    22. Dim X As Single, Y As Single
    23. Dim w As Single
    24. Dim c As Long
    25. Dim lStep As Long
    26. Dim sngStepDeg As Single
    27.  
    28. CtrlCount = Me.Controls.Count
    29. ReDim lLeft(CtrlCount)
    30. ReDim lTop(CtrlCount)
    31. ReDim sngDegree(CtrlCount)
    32. ReDim sngDistance(CtrlCount)
    33. ReDim sngStepX(CtrlCount)
    34. ReDim sngStepY(CtrlCount)
    35.  
    36. 'Initialize variables
    37. Pi = 3.141593
    38. DegRad = Pi / 180
    39. RadDeg = 180 / Pi
    40. Me.Show
    41. Me.AutoRedraw = True
    42. w = 0.1
    43. lStep = 100
    44. sngStepDeg = 5
    45.  
    46. 'Get center X and center Y
    47. cX = Me.Width \ 2
    48. cY = Me.Height \ 2
    49.  
    50. 'Save each control's original position, degree and distance from center
    51. For i = 0 To CtrlCount - 1
    52.     lLeft(i) = Me.Controls(i).Left
    53.     lTop(i) = Me.Controls(i).Top
    54.     sngDegree(i) = CSng(Atn((lTop(i) - cY) / (lLeft(i) - cX)) * RadDeg)
    55.     sngDistance(i) = CLng(Sqr(((lTop(i) - cY) ^ 2) + ((lLeft(i) - cX) ^ 2)))
    56. Next
    57.  
    58. 'Show time
    59. t = Timer + msTime
    60. Do Until Timer >= t
    61.     Me.Cls
    62.     PSet (cX, cY), 0
    63.     For i = 0 To CtrlCount - 1
    64.         Set Ctrl = Me.Controls(i)
    65.         'We increment the degree bit by bit
    66.         sngDegree(i) = (sngDegree(i) + sngStepDeg) Mod 360
    67.         'Calculate the correct position given the degree and distance
    68.         X = Cos(sngDegree(i) * DegRad) * sngDistance(i) + cX
    69.         Y = Sin(sngDegree(i) * DegRad) * sngDistance(i) + cY
    70.         'Move them
    71.         Ctrl.Move X, Y
    72.         Ctrl.Refresh
    73.         'Connect the control to the center with a line
    74.         'Me.Line -(X, Y), 0
    75.         Me.Line (cX, cY)-(X, Y), 65280 'RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
    76.     Next
    77.     Me.Refresh
    78.     w = Timer + 0.01
    79.     Do Until Timer >= w
    80.         DoEvents
    81.     Loop
    82. Loop
    83.  
    84. 'Get the gradual increase of each control
    85. For i = 0 To CtrlCount - 1
    86.     Set Ctrl = Me.Controls(i)
    87.     sngStepX(i) = (lLeft(i) - Ctrl.Left) / lStep '(msTime / 2)
    88.     sngStepY(i) = (lTop(i) - Ctrl.Top) / lStep '(msTime / 2)
    89. Next
    90.  
    91. 'Return each control to their original position gradually
    92. For c = 1 To lStep
    93.     Me.Cls
    94.     For i = 0 To CtrlCount - 1
    95.         Set Ctrl = Me.Controls(i)
    96.         X = Ctrl.Left + sngStepX(i)
    97.         Y = Ctrl.Top + sngStepY(i)
    98.         Ctrl.Move X, Y
    99.         Ctrl.Refresh
    100.         Me.Line (cX, cY)-(X, Y), 0
    101.     Next
    102.     Me.Refresh
    103.     w = Timer + 0.01 '(msTime / 2 / lStep)
    104.     Do Until Timer >= w
    105.         DoEvents
    106.     Loop
    107. Next
    108.  
    109. For i = 0 To CtrlCount - 1
    110.     Set Ctrl = Me.Controls(i)
    111.     Ctrl.Move lLeft(i), lTop(i)
    112. Next
    113. Set Ctrl = Nothing
    114. Me.Cls
    115. End Sub
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  2. #2
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: Super cool Form Effect!

    weird. although, it doesn't work with some control.. i'm not going to figure out what. it says 'Left' property cannot be read at run time

  3. #3

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: Super cool Form Effect!

    Uh oh...some controls...hmmm

    Thanks for your feedback anyway. Really appreciate it

    Mine telling me what sort of controls are those?
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Super cool Form Effect!

    Isn't this best placed in the CodeBank? You can find it here.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Super cool Form Effect!

    What would you use this for ?????
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width