Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21455

Form resizes to fill screen but the regular form size won't fit 1024x768?

$
0
0
Hi there everyone! I am working on a form that resizes to fill the screen on form load. It works beautiful, but when I was testing it on the 1024x768 resolution, and the forms size is just a little too wide for the screen. As a result the last little bit on the right side is hidden off the screen.

MY form is all frames, lines, and label captions. Would there be a way around this little snag cause this code works great on all resolutions above 1024x768, but I just need to figure out how to get it to fit the screen on 1024x768.

This would help the students who have a hard time seeing things on the interactive boards, I have been making progs for math students, but I can't get them to resize on 1024x768.

Making the form smaller is not really an option. :)

Here is my code

VB Code:
  1. Option Explicit
  2.  
  3.  
  4. Private Type ControlPositionType
  5.     Left As Single
  6.     Top As Single
  7.     Width As Single
  8.     Height As Single
  9.     FontSize As Single
  10. End Type
  11.  
  12. Private m_ControlPositions() As ControlPositionType
  13. Private m_FormWid As Single
  14. Private m_FormHgt As Single
  15. ' Save the form's and controls' dimensions.
  16. Private Sub SaveSizes()
  17. Dim i As Integer
  18. Dim ctl As Control
  19.  
  20.     ' Save the controls' positions and sizes.
  21.     ReDim m_ControlPositions(1 To Controls.Count)
  22.     i = 1
  23.     For Each ctl In Controls
  24.         With m_ControlPositions(i)
  25.             If TypeOf ctl Is Line Then
  26.                 .Left = ctl.X1
  27.                 .Top = ctl.Y1
  28.                 .Width = ctl.X2 - ctl.X1
  29.                 .Height = ctl.Y2 - ctl.Y1
  30.             Else
  31.                 .Left = ctl.Left
  32.                 .Top = ctl.Top
  33.                 .Width = ctl.Width
  34.                 .Height = ctl.Height
  35.                 On Error Resume Next
  36.                 .FontSize = ctl.Font.Size
  37.                 On Error GoTo 0
  38.             End If
  39.         End With
  40.         i = i + 1
  41.     Next ctl
  42.  
  43.     ' Save the form's size.
  44.     m_FormWid = ScaleWidth
  45.     m_FormHgt = ScaleHeight
  46. End Sub
  47.  
  48. Private Sub Form_Load()
  49.    
  50.     SaveSizes
  51.     Width = Screen.Width
  52.     Height = Screen.Height
  53. End Sub
  54. ' Arrange the controls for the new size.
  55. Private Sub ResizeControls()
  56. Dim i As Integer
  57. Dim ctl As Control
  58. Dim x_scale As Single
  59. Dim y_scale As Single
  60.  
  61.     ' Don't bother if we are minimized.
  62.     If WindowState = vbMinimized Then Exit Sub
  63.  
  64.     ' Get the form's current scale factors.
  65.     x_scale = ScaleWidth / m_FormWid
  66.     y_scale = ScaleHeight / m_FormHgt
  67.  
  68.     ' Position the controls.
  69.     i = 1
  70.     For Each ctl In Controls
  71.         With m_ControlPositions(i)
  72.             If TypeOf ctl Is Line Then
  73.                 ctl.X1 = x_scale * .Left
  74.                 ctl.Y1 = y_scale * .Top
  75.                 ctl.X2 = ctl.X1 + x_scale * .Width
  76.                 ctl.Y2 = ctl.Y1 + y_scale * .Height
  77.             Else
  78.                 ctl.Left = x_scale * .Left
  79.                 ctl.Top = y_scale * .Top
  80.                 ctl.Width = x_scale * .Width
  81.                 If Not (TypeOf ctl Is ComboBox) Then
  82.                     ' Cannot change height of ComboBoxes.
  83.                     ctl.Height = y_scale * .Height
  84.                 End If
  85.                 On Error Resume Next
  86.                 ctl.Font.Size = y_scale * .FontSize
  87.                 On Error GoTo 0
  88.             End If
  89.         End With
  90.         i = i + 1
  91.     Next ctl
  92. End Sub
  93.  
  94. Private Sub Form_Resize()
  95.     ResizeControls
  96. End Sub

Viewing all articles
Browse latest Browse all 21455

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>