• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

make a picturebox expand by increments

Hi
I have a picturebox that contains images and labels
I am trouble make it expand to the proper height-width using a timer
Private Sub Timer2_Timer() 'expand

With picOpenOptions
 .Visible = True
 .Width = .Width + 90
 .Height = .Height + 160

  If .Width >= 2025 And .Height >= 4095 Then
    Timer2.Enabled = False
  End If
sometimes the height is wrong and other times the width
How can i write this ?
End With

End Sub
0
isnoend2001
Asked:
isnoend2001
  • 5
  • 3
  • 3
1 Solution
 
LIONKINGCommented:
Are  you sure that should be an AND?
If you want to disable the timer when "either" Width >= 2025 "or" Height >= 4095, you need to change it to an OR.

Like:

With picOpenOptions
 .Visible = True
 .Width = .Width + 90
 .Height = .Height + 160

  If .Width >= 2025 Or .Height >= 4095 Then
    Timer2.Enabled = False
  End If
End With
0
 
isnoend2001Author Commented:
i had tried it using or, but changed it to and when i had trouble, but neither worked properly
i think it may be in the proportions.The pic is taller than wide, sometimes its too short
and other times the width is too short
0
 
isnoend2001Author Commented:
this seems to work at the end of the timer, but seems like a hack
If .Width >= StopWidth And .Height >= StopHeight Then
   picOpenOptions.Width = 2180
   picOpenOptions.Height = 3745
    Timer2.Enabled = False
  End If
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
LIONKINGCommented:
Have you tried evaluating the "added" width and height before actually assigning the values? Something like:

With picOpenOptions
 .Visible = True

  If .Width + 90 >= 2025 Or .Height + 160 >= 4095 Then
    Timer2.Enabled = False
else
    .Width = .Width + 90
    .Height = .Height + 160
  End If

End With
0
 
Martin LissOlder than dirtCommented:
Try this.

Private Sub Timer2_Timer() 'expand

Dim intWidth As Integer
Dim intHeight As Integer
With picOpenOptions

If .Width + 90 > 2025 Then
    intWidth = 2025
Else
    intWidth =  .Width + 90
End If

If .Height + 160 > 4095 Then
    intHeight = 4095
Else
    intHeight =  .Height + 160
End If
 .Visible = True
 .Width = intWidth
 .Height = intHeight

  If .Width = 2025 And .Height = 4095 Then
    Timer2.Enabled = False
  End If

End With

End Sub

Open in new window

0
 
isnoend2001Author Commented:
Yes I have fooled with all the numbers. I think some kind of proportion formula is needed.
0
 
Martin LissOlder than dirtCommented:
Did you try my code?
0
 
LIONKINGCommented:
What's the expected behavior and the "actual" behavior?
I assume you're not getting any errors or something like that, right?
0
 
isnoend2001Author Commented:
that works thanks
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

My profile contains links to some articles I've written that may interest you.
Marty - MVP 2009 to 2012
0
 
isnoend2001Author Commented:
the expected behavior is to restore the width and height to it's original width and height
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now