- 帖子
- 97
- 主題
- 33
- 精華
- 0
- 積分
- 129
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- office 2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2019-5-7
- 最後登錄
- 2022-8-25
|
3#
發表於 2019-7-26 13:59
| 只看該作者
有高手可以幫我看看我這樣解釋對嗎???@@- Dim ocx_First_wh As New Collection
- Dim Fomr_TopBarHeight
- Dim hWndForm As Long
- Dim IStyle As Long
-
- Private 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
- Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
- Private Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As Long
- Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
- Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
- Private Const WS_MAXIMIZEBOX = &H10000
- Private Const WS_MINIMIZEBOX = &H20000
- Private Const GWL_STYLE = (-16)
- Private Const SW_SHOWMAXIMIZED = 3
- Private Const SW_SHOWNORMAL = 1
- Private Const SW_SHOWMINIMIZED = 2
- Private Const WS_THICKFRAME = &H40000
- Const SM_CXFULLSCREEN = 16
- Const SM_CYFULLSCREEN = 17
- Const HWND_TOPMOST = -1
- Const SWP_SHOWWINDOW = &H40
-
- Private Sub CommandButton1_Click() '匯入圖面
- With Application.FileDialog(msoFileDialogFilePicker)
- .Filters.Add "ImageFile", "*.jpg; *.jpeg; *.mp4", 1
- .AllowMultiSelect = False
- If .Show = -1 Then
- Image1.Picture = LoadPicture(.SelectedItems(1))
- End If
- End With
- End Sub
- Private Sub UserForm_Initialize() '表單初始化
- 'userform最大、最小化按鈕的顯示
- hWndForm = FindWindow("ThunderDFrame", Me.Caption)
- IStyle = GetWindowLong(hWndForm, GWL_STYLE)
- IStyle = IStyle Or WS_THICKFRAME
- IStyle = IStyle Or WS_MINIMIZEBOX
- IStyle = IStyle Or WS_MAXIMIZEBOX
- SetWindowLong hWndForm, GWL_STYLE, IStyle
- '初始化視窗大小
- A = Height
- Height = 0
- Fomr_TopBarHeight = Height
- Fomr_TopBarHeight = Fix(Fomr_TopBarHeight)
- Height = A + 1.5
- With Frame1
- '這將創建一個垂直一個水平滾動條,fmScrollBarsHorizontal顯示水平捲軸,fmScrollBarsVertical顯示垂直捲軸,fmScrollBarsBoth顯示水平與垂直捲軸兩者。
- .ScrollBars = fmScrollBarsBoth
- '根據您的要求更改值2
- .ScrollHeight = .InsideHeight * 2
- .ScrollWidth = .InsideWidth * 2
- End With
- '根據產品編號自動從產品圖面資料夾匯入圖面
- imgname = ActiveWorkbook.Sheets("管制計畫表").Range("I4").Value
- Dim imgpath As String
- imgpath = "\\G-server\產品履歷\客戶\00.範本\產品圖面"
- With Image1
- .Picture = LoadPicture(imgpath & "\" & imgname & ".jpg")
- .AutoSize = True
- .BorderStyle = fmBorderStyleNone
- .PictureSizeMode = fmPictureSizeModeZoom
- End With
- With Frame1
- .BorderStyle = fmBorderStyleNone
- .PictureSizeMode = fmPictureSizeModeZoom
- End With
- End Sub
- Private Sub CommandButton3_Click() '圖像縮小鍵
- Me.Image1.Height = Me.Image1.Height - 200
- Me.Image1.Width = Me.Image1.Width - 200
- End Sub
- Private Sub CommandButton2_Click() '圖像放大鍵
- Me.Image1.Height = Me.Image1.Height + 200
- Me.Image1.Width = Me.Image1.Width + 200
- End Sub
- Public Sub myShowMax() 'userform 最大化
- SetActiveWindow hWndForm
- ShowWindow hWndForm, SW_SHOWMAXIMIZED
- End Sub
- Private Sub UserForm_Layout()
- '取得目前視窗大小
- If ocx_First_wh.Count = 0 Then
- ocx_First_wh.Add Key:="UserForm", Item:=Array(, Array(Left, Top, Width, Height, Font.Size, ""))
- On Error Resume Next
- For Each s In Controls
- ocx_First_wh.Add Key:=s.Name, Item:=Array(s, Array(s.Left, s.Top, s.Width, s.Height, s.Font.Size))
- If Err Then
- ocx_First_wh.Add Key:=s.Name, Item:=Array(s, Array(s.Left, s.Top, s.Width, s.Height, Empty))
- End If
- Next
- On Error GoTo 0
- Form_xy = GetSetting(ThisWorkbook.Name, Name, "Form_Size")
- '最大化視窗觸發時
- If Form_xy <> "" Then
- Form_xy = Split(Form_xy + String(5, ","), ",")
- If Form_xy(5) = "max" Then
- myShowMax
- Else
- On Error Resume Next
- Move Form_xy(0), Form_xy(1), Form_xy(2), Form_xy(3)
- On Error GoTo 0
- End If
- End If
- Exit Sub
- End If
- '計算視窗大小?????
- Form_xy = ocx_First_wh("UserForm")(1)
- Rw = Width / Form_xy(2)
- Rh = (Height - Fomr_TopBarHeight) / (Form_xy(3) - Fomr_TopBarHeight)
- Rwh = IIf(Rw < Rh, Rw, Rh)
- '當縮放userform時,裡面的物件也跟著變動
- For w = 2 To ocx_First_wh.Count
- Set ocx = ocx_First_wh(w)(0)
- ocx_xy = ocx_First_wh(w)(1)
- ocx.Left = ocx_xy(0) * Rw
- ocx.Top = ocx_xy(1) * Rh
- ocx.Width = ocx_xy(2) * Rw
- ocx.Height = ocx_xy(3) * Rh
- If TypeOf ocx Is CommandButton Then
- ocx.FontSize = ocx_xy(4) * Rwh
- Else
- End If
- Next
- '儲存目前視窗的大小
- On Error Resume Next
- Height = Height
- SaveSetting ThisWorkbook.Name, Name, "Form_Size", Join(Array(Left, Top, Width, Height, 0, IIf(Err, "max", "")), ",")
- End Sub
複製代碼 |
|