分享

VB窗口大小,控件自动调整的问题

 特别馆888 2019-01-28
  1. Option Explicit  
  2.   
  3. Private nWndHeight As Long  
  4. Private nWndWidth As Long  
  5. Private nControl As Long  
  6.   
  7. Private lpTop() As Long  
  8. Private lpLeft() As Long  
  9. Private lpWidth() As Long  
  10. Private lpHeight() As Long  
  11.   
  12. Private Sub Form_Load()  
  13.     Me.GetControlSize  
  14.     Me.WindowState = 2  
  15.     '......  
  16. End Sub  
  17.   
  18. Public Sub GetControlSize()  
  19.     Dim c As Control, i As Integer  
  20.     nControl = 0  
  21.     i = Me.ScaleMode  
  22.     Me.ScaleMode = 1  
  23.     On Local Error Resume Next  
  24.       
  25.     nWndWidth = Me.Width  
  26.     nWndHeight = Me.Height  
  27.     For Each c In Me.Controls  
  28.         ReDim Preserve lpTop(nControl)  
  29.         ReDim Preserve lpLeft(nControl)  
  30.         ReDim Preserve lpWidth(nControl)  
  31.         ReDim Preserve lpHeight(nControl)  
  32.         lpTop(nControl) = c.Top  
  33.         lpLeft(nControl) = c.Left  
  34.         lpWidth(nControl) = c.Width  
  35.         lpHeight(nControl) = c.Height  
  36.         nControl = nControl + 1  
  37.     Next  
  38.     Me.ScaleMode = i  
  39. End Sub  
  40.   
  41. Public Sub SetControlSize()  
  42.     '  
  43.     Dim c As Control, i As Integer  
  44.     Dim p As Long  
  45.     i = Me.ScaleMode  
  46.     Me.ScaleMode = 1  
  47.     For Each c In Me.Controls  
  48.         c.Top = Me.Height * lpTop(p) / nWndHeight  
  49.         c.Left = Me.Width * lpLeft(p) / nWndWidth  
  50.         c.Width = Me.Width * lpWidth(p) / nWndWidth  
  51.         c.Height = Me.Height * lpHeight(p) / nWndHeight  
  52.         p = p + 1  
  53.     Next  
  54.     Me.ScaleMode = i  
  55. End Sub  
  56.   
  57. Private Sub Form_Resize()  
  58.     Me.SetControlSize  
  59. End Sub  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多