?? resize.bas
字號(hào):
Attribute VB_Name = "Module1"
Private FormOldWidth As Long
'保存窗體的原始寬度
Private FormOldHeight As Long
'保存窗體的原始高度
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
'在調(diào)用ResizeForm前先調(diào)用本函數(shù)
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj
On Error GoTo 0
End Sub
'按比例改變表單內(nèi)各元件的大小,
'在調(diào)用ReSizeForm前先調(diào)用ReSizeInit函數(shù)
Public Sub ResizeForm(FormName As Form)
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double
'在調(diào)試時(shí)如果出現(xiàn)除數(shù)為零錯(cuò)誤,是因?yàn)闆](méi)有設(shè)定form的初值,請(qǐng)雙擊form1然后再測(cè)試,這個(gè)問(wèn)題絕對(duì)不會(huì)在編譯好的程序中出現(xiàn)
If FormOldWidth = 0 Then '防止該錯(cuò)誤的產(chǎn)生
Exit Sub
End If
ScaleX = FormName.ScaleWidth / FormOldWidth
'保存窗體寬度縮放比例
ScaleY = FormName.ScaleHeight / FormOldHeight
'保存窗體高度縮放比例
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For i = 0 To 4
'讀取控件的原始位置與大小
TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If
'根據(jù)控件的原始位置及窗體改變大小
'的比例對(duì)控件重新定位與改變大小
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
Next i
Next Obj
On Error GoTo 0
End Sub
Public Sub Shutdown(Optional ByVal Force As Boolean = False)
'卸載所有窗體
Dim i As Long
On Error Resume Next
For i = Forms.Count - 1 To 0 Step -1
Unload Forms(i)
If Not Force Then
If Forms.Count > i Then
Exit Sub
End If
End If
Next i
If Force Or (Forms.Count = 0) Then Close
If Force Or (Forms.Count > 0) Then End
End Sub
Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
'限制文本框只能輸入ValidateString內(nèi)的字母
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ValiText = KeyOut
End Function
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -