pherotao > 21-12-17, 02:12 PM
Private Sub Form_Open(Cancel As Integer)
CommandBars("menu bar").Enabled = True
' Laáy ñoä phaân giaûi maøn hình & ñoåi ra twips. 1 twip = 1/15 pixels; 1/20 point; 1/567 cm ; 1/1440 inch
TwipResW = GetSystemMetrics(0) * 14.948
TwipResH = GetSystemMetrics(1) * 14.435
DoCmd.MoveSize 0, 0, TwipResW - 100, TwipResH - 100
Me.Width = Me.WindowWidth
Me.Detail.Height = Me.WindowHeight
End Sub
TwipResW = GetSystemMetrics(0) * 14.948
TwipResH = GetSystemMetrics(1) * 14.435
ongke0711 > 21-12-17, 04:49 PM
pherotao > 21-12-17, 06:05 PM
(21-12-17, 04:49 PM)ongke0711 Đã viết: Form có thuộc tính Maximize sao bạn ko sử dụng.
Ở sựsự kiện Form_Open
Docmd.Maximize
ongke0711 > 21-12-17, 08:24 PM
Option Compare Database
Option Explicit
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal _
nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal _
X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
'Use following instead of GetWindowRect'
Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect _
As Rect) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Sub MaximizeRestoredForm(F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(F.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub
Private Sub Form_Load()
MaximizeRestoredForm Me
End Sub
pherotao > 21-12-17, 09:00 PM
(21-12-17, 08:24 PM)ongke0711 Đã viết: Thay thế lệnh Docmd.Maximize và vô hiệu hóa nút Restore của Window.
----------------------------------------------------------------------------------------------------------------------
Sau đây là hàm tự tạo dùng thay thế lệnh Docmd.Maximize khi bạn muốn Form sẽ bung toàn màn hình khi khởi động và vượt qua cái phiền toái là vẫn còn nút Restore trên Form lỡ khi người dùng bấm vào thì Form sẽ thu lại như ban đầu thiết kế.
- Copy code sau vào module:
Mã PHP:Option Compare Database
Option Explicit
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal _
nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal _
X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
'Use following instead of GetWindowRect'
Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect _
As Rect) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Sub MaximizeRestoredForm(F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(F.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub
- Form nào cần chạy toàn màn hình thì thiết lập sự kiện Form_Load cho nó như bên dưới.
Mã PHP:Private Sub Form_Load()
MaximizeRestoredForm Me
End Sub
ongke0711 > 21-12-17, 10:29 PM
pherotao > 21-12-17, 10:47 PM
ongke0711 > 21-12-17, 11:06 PM
pherotao > 21-12-17, 11:15 PM
(21-12-17, 11:06 PM)ongke0711 Đã viết: Bạn bỏ Border của form luôn, đã maximize cần gì Border nữa.
ongke0711 > 21-12-17, 11:38 PM