VB编程——确定客户区大小

Private Type RECT
    Left     As Long       'X坐标,0
    Top      As Long       'Y坐标,0
    Right    As Long       '相当于ScaleHeight
    Bottom   As Long       '相当于ScaleWidth
End Type

Private Declare Function GetClientRect Lib "user32 " (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Sub Form_Load()
    Form1.Width = 8000
    Form1.Height = 8000
    Picture1.Width = 7250
    Picture1.Height = 7750
    Dim MyRect As RECT
    wndCapH = 0          '标题栏高
    wndEdgeX = 0         '边框厚度
    wndEdgeY = 0         '边框高度
    GetClientRect Me.hwnd, MyRect
    wndCapH = GetSystemMetrics(4)
    Picture1.Left = (Form1.Width - MyRect.Right * 15) / 2
    Picture1.Top = (Form1.Height - wndCapH * 15 - MyRect.Bottom * 15) / 2
     
End Sub

普及小知识(摘抄于网络:https://zhidao.baidu.com/question/184933099.html

  1. 缇(Twips) ,计量单位。1厘米有 567 缇。
  2. 像素(Pixels):此处指监视器屏幕分辨率的最小单位。
  3. DPI的意思就是 DPI (Dots per Inch)。
  4. TPI的意思就是 TPI (Twips per Inch)。
  5. 1 Pixel = 1440 TPI / 96 DPI = 15 Twips。
  6. 此处1厘米=576/15=37.8像素。

猜你喜欢

转载自blog.csdn.net/lihongtao8209/article/details/103851768