?? resize.bas
字號:
Attribute VB_Name = "resize"
Option Explicit
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
'在調用ResizeForm前先調用本函數
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 & " "
'MsgBox Obj.Tag
Next 'Obj
If Obj.FontSize > 12 Then Obj.FontSize = 12
On Error GoTo 0
End Sub
'按比例改變表單內各元件的大小,
'在調用ReSizeForm前先調用ReSizeInit函數
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
'在調試時如果出現除數為零錯誤,是因為沒有設定form的初值,請雙擊form1然后再測試,這個問題絕對不會在編譯好的程序中出現
If FormOldWidth = 0 Then '防止該錯誤的產生
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
'根據控件的原始位置及窗體改變大小
'的比例對控件重新定位與改變大小
Obj.FontSize = 10 * Sqr(ScaleX * ScaleX / 2 + ScaleY * ScaleY / 2)
With frmMain.DataGrid1
.HeadFont.Size = .Width / 1000
.Font.Size = .Width / 1000
.Columns.Item(0).Width = 0
.Columns.Item(1).Width = .Width * 0.1
.Columns.Item(2).Width = .Width * 0.3
.Columns.Item(3).Width = .Width * 0.15
.Columns.Item(4).Width = .Width * 0.15
.Columns.Item(5).Width = .Width * 0.15
.Columns.Item(5).Width = .Width * 0.1
End With
If Obj.FontSize > 12 Then Obj.FontSize = 12
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內的字母
Dim ValidateList As String
Dim KeyINOUT 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
KeyINOUT = KeyIn
Else
KeyINOUT = 0
Beep
End If
ValiText = KeyINOUT
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -