|
-
May 11th, 2005, 03:29 AM
#1
Thread Starter
Fanatic Member
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:
'(C) Copyright jian2587 2005. Use freely but give credit! :)
Private Sub Form_Load()
RotateControls
End Sub
Private Sub RotateControls(Optional ByVal msTime As Single = 3)
Dim lLeft() As Long
Dim lTop() As Long
Dim sngDegree() As Single
Dim sngDistance() As Long
Dim sngStepX() As Single
Dim sngStepY() As Single
Dim CtrlCount As Long
Dim i As Long
Dim Ctrl As Control
Dim cX As Long
Dim cY As Long
Dim Pi As Double
Dim DegRad As Single
Dim RadDeg As Single
Dim t As Single
Dim X As Single, Y As Single
Dim w As Single
Dim c As Long
Dim lStep As Long
Dim sngStepDeg As Single
CtrlCount = Me.Controls.Count
ReDim lLeft(CtrlCount)
ReDim lTop(CtrlCount)
ReDim sngDegree(CtrlCount)
ReDim sngDistance(CtrlCount)
ReDim sngStepX(CtrlCount)
ReDim sngStepY(CtrlCount)
'Initialize variables
Pi = 3.141593
DegRad = Pi / 180
RadDeg = 180 / Pi
Me.Show
Me.AutoRedraw = True
w = 0.1
lStep = 100
sngStepDeg = 5
'Get center X and center Y
cX = Me.Width \ 2
cY = Me.Height \ 2
'Save each control's original position, degree and distance from center
For i = 0 To CtrlCount - 1
lLeft(i) = Me.Controls(i).Left
lTop(i) = Me.Controls(i).Top
sngDegree(i) = CSng(Atn((lTop(i) - cY) / (lLeft(i) - cX)) * RadDeg)
sngDistance(i) = CLng(Sqr(((lTop(i) - cY) ^ 2) + ((lLeft(i) - cX) ^ 2)))
Next
'Show time
t = Timer + msTime
Do Until Timer >= t
Me.Cls
PSet (cX, cY), 0
For i = 0 To CtrlCount - 1
Set Ctrl = Me.Controls(i)
'We increment the degree bit by bit
sngDegree(i) = (sngDegree(i) + sngStepDeg) Mod 360
'Calculate the correct position given the degree and distance
X = Cos(sngDegree(i) * DegRad) * sngDistance(i) + cX
Y = Sin(sngDegree(i) * DegRad) * sngDistance(i) + cY
'Move them
Ctrl.Move X, Y
Ctrl.Refresh
'Connect the control to the center with a line
'Me.Line -(X, Y), 0
Me.Line (cX, cY)-(X, Y), 65280 'RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
Next
Me.Refresh
w = Timer + 0.01
Do Until Timer >= w
DoEvents
Loop
Loop
'Get the gradual increase of each control
For i = 0 To CtrlCount - 1
Set Ctrl = Me.Controls(i)
sngStepX(i) = (lLeft(i) - Ctrl.Left) / lStep '(msTime / 2)
sngStepY(i) = (lTop(i) - Ctrl.Top) / lStep '(msTime / 2)
Next
'Return each control to their original position gradually
For c = 1 To lStep
Me.Cls
For i = 0 To CtrlCount - 1
Set Ctrl = Me.Controls(i)
X = Ctrl.Left + sngStepX(i)
Y = Ctrl.Top + sngStepY(i)
Ctrl.Move X, Y
Ctrl.Refresh
Me.Line (cX, cY)-(X, Y), 0
Next
Me.Refresh
w = Timer + 0.01 '(msTime / 2 / lStep)
Do Until Timer >= w
DoEvents
Loop
Next
For i = 0 To CtrlCount - 1
Set Ctrl = Me.Controls(i)
Ctrl.Move lLeft(i), lTop(i)
Next
Set Ctrl = Nothing
Me.Cls
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
-
May 11th, 2005, 03:40 AM
#2
Frenzied Member
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
-
May 11th, 2005, 03:49 AM
#3
Thread Starter
Fanatic Member
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
-
May 11th, 2005, 04:14 AM
#4
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
-
May 11th, 2005, 04:42 AM
#5
Frenzied Member
Re: Super cool Form Effect!
What would you use this for ?????
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|