程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> VB中控件大小隨窗體大小變化

VB中控件大小隨窗體大小變化

編輯:VB綜合教程

  有時窗體變化後,如改變分辨率後控件大小卻不能隨之改變。手工代碼調整實在麻煩,下面的模塊實現自動查找窗體上控件並使其改變大小以適應窗體變化。

  在Form的Resize事件中調用函數Resize_All就能實現控件自動調整大小,如:

  Private Sub Form_Resize()
  Dim H, i As Integer
  On Error Resume Next
  Resize_ALL Me 'Me是窗體名,Form1,Form2等等都可以

  End Sub

  在模塊中添加以下代碼:

  Public Type ctrObj
  Name As String
  Index As Long
  Parrent As String
  Top As Long
  Left As Long
  Height As Long
  Width As Long
  ScaleHeight As Long
  ScaleWidth As Long
  End Type

  Private FormRecord() As ctrObj
  Private ControlRecord() As ctrObj
  Private bRunning As Boolean
  Private MaxForm As Long
  Private MaxControl As Long
  Private Const WM_NCLBUTTONDOWN = &HA1
  Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Private Declare Function ReleaseCapture Lib "USER32" () As Long

  Function ActualPos(plLeft As Long) As Long

  If plLeft < 0 Then
  ActualPos = plLeft + 75000
  Else
  ActualPos = plLeft
  End If

  End Function

  Function FindForm(pfrmIn As Form) As Long

  Dim i As Long
  FindForm = -1

  If MaxForm > 0 Then
  
  For i = 0 To (MaxForm - 1)
   If FormRecord(i).Name = pfrmIn.Name Then
    FindForm = i
    Exit Function
   End If
  Next i
  End If

  End Function

  Function AddForm(pfrmIn As Form) As Long

  Dim FormControl As Control
  Dim i As Long
  ReDim Preserve FormRecord(MaxForm + 1)

  FormRecord(MaxForm).Name = pfrmIn.Name
  FormRecord(MaxForm).Top = pfrmIn.Top
  FormRecord(MaxForm).Left = pfrmIn.Left
  FormRecord(MaxForm).Height = pfrmIn.Height
  FormRecord(MaxForm).Width = pfrmIn.Width
  FormRecord(MaxForm).ScaleHeight = pfrmIn.ScaleHeight
  FormRecord(MaxForm).ScaleWidth = pfrmIn.ScaleWidth
  AddForm = MaxForm
  MaxForm = MaxForm + 1

  • 首頁
  • 上一頁
  • 1
  • 2
  • 3
  • 下一頁
  • 尾頁
  • 共3頁
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved