Animate Width Of a Frame Starting From Right To Left In Vb6
I'm showing some stock details to the user when a particular text box is lost focus, and because of less space on form i,m using a frame.i want to increase the width of the frame on which the stock labels are placed, Now i want it to increase starting from right to left with time stamp. Because the frame is placed on right side it has to start increasing width from right. i couldn't find any property on code snippet to do so..i any one has any idea, please assist me with that
i have used the normal width increase
If FrameYarnDtl.Width = 15 Then
FrameYarnDtl.Width = 2100
ElseIf FrameYarnDtl.Width = 2100 Then
FrameYarnDtl.Width = 4200
ElseIf FrameYarnDtl.Width = 4200 Then
FrameYarnDtl.Width = 6300
End If
If FrameYarnDtl.Width = 6300 Then
Timer1.Enabled = False
End If
vb6
add a comment |
I'm showing some stock details to the user when a particular text box is lost focus, and because of less space on form i,m using a frame.i want to increase the width of the frame on which the stock labels are placed, Now i want it to increase starting from right to left with time stamp. Because the frame is placed on right side it has to start increasing width from right. i couldn't find any property on code snippet to do so..i any one has any idea, please assist me with that
i have used the normal width increase
If FrameYarnDtl.Width = 15 Then
FrameYarnDtl.Width = 2100
ElseIf FrameYarnDtl.Width = 2100 Then
FrameYarnDtl.Width = 4200
ElseIf FrameYarnDtl.Width = 4200 Then
FrameYarnDtl.Width = 6300
End If
If FrameYarnDtl.Width = 6300 Then
Timer1.Enabled = False
End If
vb6
add a comment |
I'm showing some stock details to the user when a particular text box is lost focus, and because of less space on form i,m using a frame.i want to increase the width of the frame on which the stock labels are placed, Now i want it to increase starting from right to left with time stamp. Because the frame is placed on right side it has to start increasing width from right. i couldn't find any property on code snippet to do so..i any one has any idea, please assist me with that
i have used the normal width increase
If FrameYarnDtl.Width = 15 Then
FrameYarnDtl.Width = 2100
ElseIf FrameYarnDtl.Width = 2100 Then
FrameYarnDtl.Width = 4200
ElseIf FrameYarnDtl.Width = 4200 Then
FrameYarnDtl.Width = 6300
End If
If FrameYarnDtl.Width = 6300 Then
Timer1.Enabled = False
End If
vb6
I'm showing some stock details to the user when a particular text box is lost focus, and because of less space on form i,m using a frame.i want to increase the width of the frame on which the stock labels are placed, Now i want it to increase starting from right to left with time stamp. Because the frame is placed on right side it has to start increasing width from right. i couldn't find any property on code snippet to do so..i any one has any idea, please assist me with that
i have used the normal width increase
If FrameYarnDtl.Width = 15 Then
FrameYarnDtl.Width = 2100
ElseIf FrameYarnDtl.Width = 2100 Then
FrameYarnDtl.Width = 4200
ElseIf FrameYarnDtl.Width = 4200 Then
FrameYarnDtl.Width = 6300
End If
If FrameYarnDtl.Width = 6300 Then
Timer1.Enabled = False
End If
vb6
vb6
asked Jan 1 at 8:08
MpsMps
529
529
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Since it's the New Year...
Hint: Reduce FrameYarnDtl.Left
as FrameYarnDtl.Width
increases.
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
add a comment |
John Eason already fixed your problem, but if you wanted a working snippet here is one:
EDIT: you don't need to add any controls to the form just copy and paste the snippet.
Option Explicit
'*****************************************************************
'Author: https://stackoverflow.com/users/4938616/david
'Source: https://stackoverflow.com/q/53993968/4938616
'*****************************************************************
Private WithEvents tmrAnim As Timer
Private fraContainer As Frame
Private WithEvents btnStart As CommandButton
Private Sub btnStart_Click()
Static dir_switch As Boolean
'runs animation
Call runAnim(dir_switch)
'toggles the direction of the animation
dir_switch = Not dir_switch
End Sub
'Call this function from wherever you need to trigger the animation
Private Sub runAnim(ByVal runBackwards As Boolean)
Call timerCallback(-1, runBackwards)
tmrAnim.Enabled = True
End Sub
'timer event that updates the key frames
Private Sub tmrAnim_Timer()
Static key As Long
'function returns true when the it's done with the animation
'it is provided with a keyframe
If timerCallback(key) Then
key = 0
tmrAnim.Enabled = False
End If
'keyframe update
key = key + 1
End Sub
'this function is called from the timer and does the actual animation
Private Function timerCallback(ByRef key As Long, Optional ByRef runBack As Boolean = False) As Boolean
Static backwardAnim As Boolean 'determines the direction the animation should occur
'When key is negative this function is being called to set up its forwardAnim variable.
'This is not a clean solution, it's just a quick workaround
If key < 0 Then
backwardAnim = runBack
Exit Function
End If
'variables that keep track of animation flow
Dim kLeft As Long, kWidth As Long
'constants that store the ranges for the animation
'these could be global, but I don't like global variables
Const INI_LEFT As Long = 10, END_LEFT As Long = 170
Const INI_WIDTH As Long = 320, END_WIDTH As Long = 160
'determines the last key frame in the animation (inclusive)
Const MAX_KEY As Long = 8
Dim progress As Single
'determines the direction of the animation progress
If Not backwardAnim Then
progress = key / MAX_KEY
Else
progress = (MAX_KEY - key) / MAX_KEY
End If
'This is just a linear function of the form "c = a - (a - b) * n"
'where a and b are two arbitrary points, and c is any point in between
'a and b when 0 <= n < 1
fraContainer.Left = INI_LEFT - (INI_LEFT - END_LEFT) * progress
fraContainer.Width = INI_WIDTH - (INI_WIDTH - END_WIDTH) * progress
'returns value to caller (timer) to determine when to stop
timerCallback = key = MAX_KEY
End Function
'Inititalizes the controls added programmatically
'it's here to the bottom because it's not relevant for the purposes of this example
Private Sub Form_Load()
Set tmrAnim = Me.Controls.Add("VB.Timer", "tmrAnim", Me)
Set fraContainer = Me.Controls.Add("VB.Frame", "fraContainer", Me)
Set btnStart = Me.Controls.Add("VB.CommandButton", "btnStart", fraContainer)
Me.ScaleMode = vbTwips
Me.Width = (Me.Width - Me.ScaleWidth) + 340 * VB.Screen.TwipsPerPixelX
Me.Height = (Me.Height - Me.ScaleHeight) + 260 * VB.Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
'Initialize timer object properties
With tmrAnim
.Interval = 16 'cycles ~ every 25 milliseconds
.Enabled = False
End With
'Initialize frame object properties
With fraContainer
.Caption = "Placeholder text"
.Move 10, 10, 320, 240
.Visible = True
End With
'Initialize CommandButton object properties
With btnStart
.Default = True
.Caption = "Start Animation"
'This button's parent is a frame and frames don't inherit or can change their scale mode.
'Default are Twips which are 8 times bigger than pixels
.Move 10 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX, 120 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX
.Visible = True
End With
End Sub
- The timer that generates keyframes
- Within the timer event I call
timerCallback
that receives a keyframe and manages the animation - Constants within
timerCallback
control the beginning and ending of the animation as well as how many keyframes there is going to be - The timer is enabled by a function called
runAnim
runAnim
can be called from anywhere you wish to enable the animation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993968%2fanimate-width-of-a-frame-starting-from-right-to-left-in-vb6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since it's the New Year...
Hint: Reduce FrameYarnDtl.Left
as FrameYarnDtl.Width
increases.
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
add a comment |
Since it's the New Year...
Hint: Reduce FrameYarnDtl.Left
as FrameYarnDtl.Width
increases.
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
add a comment |
Since it's the New Year...
Hint: Reduce FrameYarnDtl.Left
as FrameYarnDtl.Width
increases.
Since it's the New Year...
Hint: Reduce FrameYarnDtl.Left
as FrameYarnDtl.Width
increases.
answered Jan 1 at 9:21
John EasonJohn Eason
862
862
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
add a comment |
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
Ooops! Happy New Year
– Mps
Jan 1 at 9:40
You're welcome! :^)
– John Eason
Jan 1 at 11:34
You're welcome! :^)
– John Eason
Jan 1 at 11:34
add a comment |
John Eason already fixed your problem, but if you wanted a working snippet here is one:
EDIT: you don't need to add any controls to the form just copy and paste the snippet.
Option Explicit
'*****************************************************************
'Author: https://stackoverflow.com/users/4938616/david
'Source: https://stackoverflow.com/q/53993968/4938616
'*****************************************************************
Private WithEvents tmrAnim As Timer
Private fraContainer As Frame
Private WithEvents btnStart As CommandButton
Private Sub btnStart_Click()
Static dir_switch As Boolean
'runs animation
Call runAnim(dir_switch)
'toggles the direction of the animation
dir_switch = Not dir_switch
End Sub
'Call this function from wherever you need to trigger the animation
Private Sub runAnim(ByVal runBackwards As Boolean)
Call timerCallback(-1, runBackwards)
tmrAnim.Enabled = True
End Sub
'timer event that updates the key frames
Private Sub tmrAnim_Timer()
Static key As Long
'function returns true when the it's done with the animation
'it is provided with a keyframe
If timerCallback(key) Then
key = 0
tmrAnim.Enabled = False
End If
'keyframe update
key = key + 1
End Sub
'this function is called from the timer and does the actual animation
Private Function timerCallback(ByRef key As Long, Optional ByRef runBack As Boolean = False) As Boolean
Static backwardAnim As Boolean 'determines the direction the animation should occur
'When key is negative this function is being called to set up its forwardAnim variable.
'This is not a clean solution, it's just a quick workaround
If key < 0 Then
backwardAnim = runBack
Exit Function
End If
'variables that keep track of animation flow
Dim kLeft As Long, kWidth As Long
'constants that store the ranges for the animation
'these could be global, but I don't like global variables
Const INI_LEFT As Long = 10, END_LEFT As Long = 170
Const INI_WIDTH As Long = 320, END_WIDTH As Long = 160
'determines the last key frame in the animation (inclusive)
Const MAX_KEY As Long = 8
Dim progress As Single
'determines the direction of the animation progress
If Not backwardAnim Then
progress = key / MAX_KEY
Else
progress = (MAX_KEY - key) / MAX_KEY
End If
'This is just a linear function of the form "c = a - (a - b) * n"
'where a and b are two arbitrary points, and c is any point in between
'a and b when 0 <= n < 1
fraContainer.Left = INI_LEFT - (INI_LEFT - END_LEFT) * progress
fraContainer.Width = INI_WIDTH - (INI_WIDTH - END_WIDTH) * progress
'returns value to caller (timer) to determine when to stop
timerCallback = key = MAX_KEY
End Function
'Inititalizes the controls added programmatically
'it's here to the bottom because it's not relevant for the purposes of this example
Private Sub Form_Load()
Set tmrAnim = Me.Controls.Add("VB.Timer", "tmrAnim", Me)
Set fraContainer = Me.Controls.Add("VB.Frame", "fraContainer", Me)
Set btnStart = Me.Controls.Add("VB.CommandButton", "btnStart", fraContainer)
Me.ScaleMode = vbTwips
Me.Width = (Me.Width - Me.ScaleWidth) + 340 * VB.Screen.TwipsPerPixelX
Me.Height = (Me.Height - Me.ScaleHeight) + 260 * VB.Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
'Initialize timer object properties
With tmrAnim
.Interval = 16 'cycles ~ every 25 milliseconds
.Enabled = False
End With
'Initialize frame object properties
With fraContainer
.Caption = "Placeholder text"
.Move 10, 10, 320, 240
.Visible = True
End With
'Initialize CommandButton object properties
With btnStart
.Default = True
.Caption = "Start Animation"
'This button's parent is a frame and frames don't inherit or can change their scale mode.
'Default are Twips which are 8 times bigger than pixels
.Move 10 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX, 120 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX
.Visible = True
End With
End Sub
- The timer that generates keyframes
- Within the timer event I call
timerCallback
that receives a keyframe and manages the animation - Constants within
timerCallback
control the beginning and ending of the animation as well as how many keyframes there is going to be - The timer is enabled by a function called
runAnim
runAnim
can be called from anywhere you wish to enable the animation.
add a comment |
John Eason already fixed your problem, but if you wanted a working snippet here is one:
EDIT: you don't need to add any controls to the form just copy and paste the snippet.
Option Explicit
'*****************************************************************
'Author: https://stackoverflow.com/users/4938616/david
'Source: https://stackoverflow.com/q/53993968/4938616
'*****************************************************************
Private WithEvents tmrAnim As Timer
Private fraContainer As Frame
Private WithEvents btnStart As CommandButton
Private Sub btnStart_Click()
Static dir_switch As Boolean
'runs animation
Call runAnim(dir_switch)
'toggles the direction of the animation
dir_switch = Not dir_switch
End Sub
'Call this function from wherever you need to trigger the animation
Private Sub runAnim(ByVal runBackwards As Boolean)
Call timerCallback(-1, runBackwards)
tmrAnim.Enabled = True
End Sub
'timer event that updates the key frames
Private Sub tmrAnim_Timer()
Static key As Long
'function returns true when the it's done with the animation
'it is provided with a keyframe
If timerCallback(key) Then
key = 0
tmrAnim.Enabled = False
End If
'keyframe update
key = key + 1
End Sub
'this function is called from the timer and does the actual animation
Private Function timerCallback(ByRef key As Long, Optional ByRef runBack As Boolean = False) As Boolean
Static backwardAnim As Boolean 'determines the direction the animation should occur
'When key is negative this function is being called to set up its forwardAnim variable.
'This is not a clean solution, it's just a quick workaround
If key < 0 Then
backwardAnim = runBack
Exit Function
End If
'variables that keep track of animation flow
Dim kLeft As Long, kWidth As Long
'constants that store the ranges for the animation
'these could be global, but I don't like global variables
Const INI_LEFT As Long = 10, END_LEFT As Long = 170
Const INI_WIDTH As Long = 320, END_WIDTH As Long = 160
'determines the last key frame in the animation (inclusive)
Const MAX_KEY As Long = 8
Dim progress As Single
'determines the direction of the animation progress
If Not backwardAnim Then
progress = key / MAX_KEY
Else
progress = (MAX_KEY - key) / MAX_KEY
End If
'This is just a linear function of the form "c = a - (a - b) * n"
'where a and b are two arbitrary points, and c is any point in between
'a and b when 0 <= n < 1
fraContainer.Left = INI_LEFT - (INI_LEFT - END_LEFT) * progress
fraContainer.Width = INI_WIDTH - (INI_WIDTH - END_WIDTH) * progress
'returns value to caller (timer) to determine when to stop
timerCallback = key = MAX_KEY
End Function
'Inititalizes the controls added programmatically
'it's here to the bottom because it's not relevant for the purposes of this example
Private Sub Form_Load()
Set tmrAnim = Me.Controls.Add("VB.Timer", "tmrAnim", Me)
Set fraContainer = Me.Controls.Add("VB.Frame", "fraContainer", Me)
Set btnStart = Me.Controls.Add("VB.CommandButton", "btnStart", fraContainer)
Me.ScaleMode = vbTwips
Me.Width = (Me.Width - Me.ScaleWidth) + 340 * VB.Screen.TwipsPerPixelX
Me.Height = (Me.Height - Me.ScaleHeight) + 260 * VB.Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
'Initialize timer object properties
With tmrAnim
.Interval = 16 'cycles ~ every 25 milliseconds
.Enabled = False
End With
'Initialize frame object properties
With fraContainer
.Caption = "Placeholder text"
.Move 10, 10, 320, 240
.Visible = True
End With
'Initialize CommandButton object properties
With btnStart
.Default = True
.Caption = "Start Animation"
'This button's parent is a frame and frames don't inherit or can change their scale mode.
'Default are Twips which are 8 times bigger than pixels
.Move 10 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX, 120 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX
.Visible = True
End With
End Sub
- The timer that generates keyframes
- Within the timer event I call
timerCallback
that receives a keyframe and manages the animation - Constants within
timerCallback
control the beginning and ending of the animation as well as how many keyframes there is going to be - The timer is enabled by a function called
runAnim
runAnim
can be called from anywhere you wish to enable the animation.
add a comment |
John Eason already fixed your problem, but if you wanted a working snippet here is one:
EDIT: you don't need to add any controls to the form just copy and paste the snippet.
Option Explicit
'*****************************************************************
'Author: https://stackoverflow.com/users/4938616/david
'Source: https://stackoverflow.com/q/53993968/4938616
'*****************************************************************
Private WithEvents tmrAnim As Timer
Private fraContainer As Frame
Private WithEvents btnStart As CommandButton
Private Sub btnStart_Click()
Static dir_switch As Boolean
'runs animation
Call runAnim(dir_switch)
'toggles the direction of the animation
dir_switch = Not dir_switch
End Sub
'Call this function from wherever you need to trigger the animation
Private Sub runAnim(ByVal runBackwards As Boolean)
Call timerCallback(-1, runBackwards)
tmrAnim.Enabled = True
End Sub
'timer event that updates the key frames
Private Sub tmrAnim_Timer()
Static key As Long
'function returns true when the it's done with the animation
'it is provided with a keyframe
If timerCallback(key) Then
key = 0
tmrAnim.Enabled = False
End If
'keyframe update
key = key + 1
End Sub
'this function is called from the timer and does the actual animation
Private Function timerCallback(ByRef key As Long, Optional ByRef runBack As Boolean = False) As Boolean
Static backwardAnim As Boolean 'determines the direction the animation should occur
'When key is negative this function is being called to set up its forwardAnim variable.
'This is not a clean solution, it's just a quick workaround
If key < 0 Then
backwardAnim = runBack
Exit Function
End If
'variables that keep track of animation flow
Dim kLeft As Long, kWidth As Long
'constants that store the ranges for the animation
'these could be global, but I don't like global variables
Const INI_LEFT As Long = 10, END_LEFT As Long = 170
Const INI_WIDTH As Long = 320, END_WIDTH As Long = 160
'determines the last key frame in the animation (inclusive)
Const MAX_KEY As Long = 8
Dim progress As Single
'determines the direction of the animation progress
If Not backwardAnim Then
progress = key / MAX_KEY
Else
progress = (MAX_KEY - key) / MAX_KEY
End If
'This is just a linear function of the form "c = a - (a - b) * n"
'where a and b are two arbitrary points, and c is any point in between
'a and b when 0 <= n < 1
fraContainer.Left = INI_LEFT - (INI_LEFT - END_LEFT) * progress
fraContainer.Width = INI_WIDTH - (INI_WIDTH - END_WIDTH) * progress
'returns value to caller (timer) to determine when to stop
timerCallback = key = MAX_KEY
End Function
'Inititalizes the controls added programmatically
'it's here to the bottom because it's not relevant for the purposes of this example
Private Sub Form_Load()
Set tmrAnim = Me.Controls.Add("VB.Timer", "tmrAnim", Me)
Set fraContainer = Me.Controls.Add("VB.Frame", "fraContainer", Me)
Set btnStart = Me.Controls.Add("VB.CommandButton", "btnStart", fraContainer)
Me.ScaleMode = vbTwips
Me.Width = (Me.Width - Me.ScaleWidth) + 340 * VB.Screen.TwipsPerPixelX
Me.Height = (Me.Height - Me.ScaleHeight) + 260 * VB.Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
'Initialize timer object properties
With tmrAnim
.Interval = 16 'cycles ~ every 25 milliseconds
.Enabled = False
End With
'Initialize frame object properties
With fraContainer
.Caption = "Placeholder text"
.Move 10, 10, 320, 240
.Visible = True
End With
'Initialize CommandButton object properties
With btnStart
.Default = True
.Caption = "Start Animation"
'This button's parent is a frame and frames don't inherit or can change their scale mode.
'Default are Twips which are 8 times bigger than pixels
.Move 10 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX, 120 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX
.Visible = True
End With
End Sub
- The timer that generates keyframes
- Within the timer event I call
timerCallback
that receives a keyframe and manages the animation - Constants within
timerCallback
control the beginning and ending of the animation as well as how many keyframes there is going to be - The timer is enabled by a function called
runAnim
runAnim
can be called from anywhere you wish to enable the animation.
John Eason already fixed your problem, but if you wanted a working snippet here is one:
EDIT: you don't need to add any controls to the form just copy and paste the snippet.
Option Explicit
'*****************************************************************
'Author: https://stackoverflow.com/users/4938616/david
'Source: https://stackoverflow.com/q/53993968/4938616
'*****************************************************************
Private WithEvents tmrAnim As Timer
Private fraContainer As Frame
Private WithEvents btnStart As CommandButton
Private Sub btnStart_Click()
Static dir_switch As Boolean
'runs animation
Call runAnim(dir_switch)
'toggles the direction of the animation
dir_switch = Not dir_switch
End Sub
'Call this function from wherever you need to trigger the animation
Private Sub runAnim(ByVal runBackwards As Boolean)
Call timerCallback(-1, runBackwards)
tmrAnim.Enabled = True
End Sub
'timer event that updates the key frames
Private Sub tmrAnim_Timer()
Static key As Long
'function returns true when the it's done with the animation
'it is provided with a keyframe
If timerCallback(key) Then
key = 0
tmrAnim.Enabled = False
End If
'keyframe update
key = key + 1
End Sub
'this function is called from the timer and does the actual animation
Private Function timerCallback(ByRef key As Long, Optional ByRef runBack As Boolean = False) As Boolean
Static backwardAnim As Boolean 'determines the direction the animation should occur
'When key is negative this function is being called to set up its forwardAnim variable.
'This is not a clean solution, it's just a quick workaround
If key < 0 Then
backwardAnim = runBack
Exit Function
End If
'variables that keep track of animation flow
Dim kLeft As Long, kWidth As Long
'constants that store the ranges for the animation
'these could be global, but I don't like global variables
Const INI_LEFT As Long = 10, END_LEFT As Long = 170
Const INI_WIDTH As Long = 320, END_WIDTH As Long = 160
'determines the last key frame in the animation (inclusive)
Const MAX_KEY As Long = 8
Dim progress As Single
'determines the direction of the animation progress
If Not backwardAnim Then
progress = key / MAX_KEY
Else
progress = (MAX_KEY - key) / MAX_KEY
End If
'This is just a linear function of the form "c = a - (a - b) * n"
'where a and b are two arbitrary points, and c is any point in between
'a and b when 0 <= n < 1
fraContainer.Left = INI_LEFT - (INI_LEFT - END_LEFT) * progress
fraContainer.Width = INI_WIDTH - (INI_WIDTH - END_WIDTH) * progress
'returns value to caller (timer) to determine when to stop
timerCallback = key = MAX_KEY
End Function
'Inititalizes the controls added programmatically
'it's here to the bottom because it's not relevant for the purposes of this example
Private Sub Form_Load()
Set tmrAnim = Me.Controls.Add("VB.Timer", "tmrAnim", Me)
Set fraContainer = Me.Controls.Add("VB.Frame", "fraContainer", Me)
Set btnStart = Me.Controls.Add("VB.CommandButton", "btnStart", fraContainer)
Me.ScaleMode = vbTwips
Me.Width = (Me.Width - Me.ScaleWidth) + 340 * VB.Screen.TwipsPerPixelX
Me.Height = (Me.Height - Me.ScaleHeight) + 260 * VB.Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
'Initialize timer object properties
With tmrAnim
.Interval = 16 'cycles ~ every 25 milliseconds
.Enabled = False
End With
'Initialize frame object properties
With fraContainer
.Caption = "Placeholder text"
.Move 10, 10, 320, 240
.Visible = True
End With
'Initialize CommandButton object properties
With btnStart
.Default = True
.Caption = "Start Animation"
'This button's parent is a frame and frames don't inherit or can change their scale mode.
'Default are Twips which are 8 times bigger than pixels
.Move 10 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX, 120 * VB.Screen.TwipsPerPixelX, 20 * VB.Screen.TwipsPerPixelX
.Visible = True
End With
End Sub
- The timer that generates keyframes
- Within the timer event I call
timerCallback
that receives a keyframe and manages the animation - Constants within
timerCallback
control the beginning and ending of the animation as well as how many keyframes there is going to be - The timer is enabled by a function called
runAnim
runAnim
can be called from anywhere you wish to enable the animation.
edited Jan 1 at 23:18
answered Jan 1 at 23:13
DavidDavid
266
266
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993968%2fanimate-width-of-a-frame-starting-from-right-to-left-in-vb6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown