Problem in resizing forms........

Thread Solved
Reply

Join Date: Nov 2007
Posts: 58
Reputation: guest11 is an unknown quantity at this point 
Solved Threads: 2
guest11 guest11 is offline Offline
Junior Poster in Training

Problem in resizing forms........

 
0
  #1
Mar 17th, 2009
hi all,

I have one problem with resizing forms.

I am developing our application in vb and i gave code for resizing forms in resize event of form. First i save the sizes of all controls in forms in form load event and then in resize event i resizes all controls of form. So that my application can run on any screen resolution.
My problem is i am using tab control for what is happening is whatever tab is active at the time of running application that controls are visible to me but other tabs controls are not visible.
When i debug the application i found that other controls left value is coming in minus that is -68940.
That's why control is not visible to user after resizing it. I am getting the problem.
Can anybody tell me what is the problem with solution.

Thanks in advance.

Regards
Guest11
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 762
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 134
vb5prgrmr vb5prgrmr is offline Offline
Master Poster

Re: Problem in resizing forms........

 
0
  #2
Mar 17th, 2009
g_8306 @ vbforums? See replies there
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Problem in resizing forms........

 
0
  #3
Mar 17th, 2009
In a form_resize event your form will resize. What will not resize and relocate automatically are your controls. They will remain at the locations originally specified in the design view.

So your problem is how do I write code to resize and relocate my controls?

Use ratios. Use ratios. Use ratios. Use ratios. Use ratios. Use algebra. Use algebra. Use Equations.

This is one example.

Find the new left position:

Ratio Formula
Original Width/ New Width = Original Left/ New Left

You know the original width of your form. Let's say it is 2200. After a resize event, it changes to 2800. And you know the current left position of your control:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim lngLeft as long
  2. lngLeft = MyControl.Left
Use your formula:
2200 / 2800 = lngLeft / New Left
The only value you don't know is New Left.

Cross Multiply to solve a ratio Equation: Multiply tops * bottoms. If you know algebra, then you should be able to figure this out.


But in the example it works like this:

2200 * New Left = 2800 * lngLeft


To solve this equation isolate NewLeft:

NewLeft = (2800 * lngLeft) / 2200

You have just solved for the left position of one control.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. MyControl.left = NewLeft

Use the same principle for solving for the top value, but use a different formula:

Original Height / New Height = lngTop / NewTop

In the resize event, you first extract the New Height. extract the current top value of your control. and then use the formula to figure out the NewTop value.

Do the same for Width and Height values of the control.

Original Width / NewWidth = MyControl.Width / NewControlWidth

Isolate the only unknown value in the above equation (New Control Width) as above and set the width as before
Mycontrol.Width = NewControlWidth

Same for Height:

I'll let you figure that out equation.


But another problem that you'll face is how do I deal with 50 controls of different types?

I personally use the Controls Collection in VB6. You can stick this code inside your form in the appropriate places.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Dim lngCurrentWidth as long, lngCurrentHeight as long
  3.  
  4. Private Sub Form_Load
  5. lngCurrentWidth = Me.Width
  6. lngCurrentHeight = Me.Height
  7. End Sub
  8.  
  9. Private Sub Form_Resize()
  10. On error Resume Next
  11. Dim ctl as Control
  12. dim strName as string
  13. dim lngNewWidth as long, lngNewHeight as long
  14.  
  15. lngNewWidth = Me.Width
  16. lngNewHeight = Me.Height
  17.  
  18. For each ctl in Me ' Me would refer to the form
  19. ' Find out which control with the TypeName function
  20. strName = TypeName(ctl)
  21.  
  22. ' You can deal with different controls in the same
  23. ' way or differently to suit your program using a
  24. ' Select Case Logic structure.
  25.  
  26. Select Case strName
  27. Case "CommandButton", "Label", "TextBox"
  28. ' Code to deal with left, height, Width, and Height
  29. lngLeft = ctl.left
  30. lngTop = ctl.Top
  31. lngWidth = ctl.Width
  32. lngHeight = ctl.Height
  33. ' Solve your formulas here and assign the values to the control
  34. ctl.left = WhateverVariable you've declared for this
  35. ctl.Top = '[ ......
  36. ctl.Width = ' ..................
  37. ' etc.
  38. Case "PictureBox"
  39. ' Code to deal with left, height, Width, and Height
  40. Case Else
  41. End Select
  42. Next
  43.  
  44. lngCurrentWidth = lngNewWidth
  45. lngCurrentHeight = lngNewHeight
  46.  
  47. End Sub
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 58
Reputation: guest11 is an unknown quantity at this point 
Solved Threads: 2
guest11 guest11 is offline Offline
Junior Poster in Training

Re: Problem in resizing forms........

 
0
  #4
Mar 18th, 2009
I use the same concept. But when i calculate the current left value then i got that value in minus(value i got is -68550). So whenever i try to calculate the new position using current left value i got that value in minus that is less than zero value and that's why it is not visible to user.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Problem in resizing forms........

 
0
  #5
Mar 18th, 2009
I don't know. It's hard to tell from the info you've given, but really the only 2 values you need to keep track of are the current width and the current height of the form. You notice I track them immediately upon the Form_Load event and at the end of the resize event.

And you should also notice that there is an On Error Resume Next statement at the beginning of the Form_Resize event. Usually, those negative values come from minimizing the window or coming up with a value that doesn't make sense. You may have to write an error loop to catch those negative values in the resize event and make sure that the current width and current height values of the form are not negative. Once they change to negative, you may have problems changing them back.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 58
Reputation: guest11 is an unknown quantity at this point 
Solved Threads: 2
guest11 guest11 is offline Offline
Junior Poster in Training

Re: Problem in resizing forms........

 
0
  #6
Mar 19th, 2009
hi hkdani,

thanks for your support i got my problem. Actually i had taken all controls on tab control, and that's why i am facing that negative value problem. But now i got the solution thanks alot for your support.


Regards
guest11
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC