登录 注册 会员中心 升级会员
电脑打印机维修|有声小说|软件下载|破解软件|小说下载|系统下载|aww255.com aww255.net

维 修 手 册

兄 弟  夏 普  施 乐   理 光  京 瓷  佳 能   惠 普   东 芝  爱普生   奔 图   柯 美   三 星   联 想  OKI  奇 普  其 他

当前位置:网站首页 > 维修资料 > 电脑网络维修 > 正文

VB窗体初始最大化和改变窗体大小自动缩放控件及字体

作者:米爸爸发布时间:2023-12-18分类:电脑网络维修浏览:900评论:0


导读:1、模块代码:'标准模块声明写入(自定义类型)Type cp    wp As Single...

ca49c02ac0fbdb00c2d9ce1a682efdf4_4717e3433d32f4dda61aa8dba7c61f3d.gif

1、模块代码:

'标准模块声明写入(自定义类型)
Type cp
    wp As Single
    hp As Single
    tp As Single
    lp As Single
    fp As Single
End Type
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
'屏幕尺寸
Private Declare Function GetSystemMetrics32 Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Public ap() As cp  '定义窗体数组
'屏幕宽
Function ScreenWidth() As Long
    ScreenWidth = GetSystemMetrics32(0) * 15
End Function
'屏幕高,去除底部状态栏高度
Function ScreenHeight() As Long
    ScreenHeight = (GetSystemMetrics32(1) - 40) * 15
End Function
Public Function MyGetWinDirectory() As String
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = String(255, 0)
    lSize = GetWindowsDirectory(sBuffer, Len(sBuffer))
    sBuffer = Left(sBuffer, lSize)
    sBuffer = sBuffer + "\"
    MyGetWinDirectory = sBuffer
End Function
'定义窗体过程
Public Sub GetControlsSize(ByVal fm As Form)
    On Error GoTo uerror   '跳过无width属性控件
    With fm
        For i = 0 To .Controls.Count - 1
            ap(i).wp = .Controls(i).Width / .ScaleWidth
            ap(i).hp = .Controls(i).Height / .ScaleHeight
            ap(i).lp = .Controls(i).Left / .ScaleWidth
            ap(i).tp = .Controls(i).Top / .ScaleHeight
            ap(i).fp = .Controls(i).Font.Size / (.Controls(i).Width * .Controls(i).Height)
        Next i
    End With
    Exit Sub
uerror:
    Resume Next
End Sub

2、窗体代码

'加载窗体
Private Sub Form_Load()
    '获取每个控件大小比例
    On Error GoTo uerror
    ReDim ap(0 To Me.Controls.Count - 1)
uerror:
    Resume Next
    GetControlsSize Me
    '窗口最大化
    Me.Left = 0
    Me.Top = 0
    Me.Width = ScreenWidth
    Me.Height = ScreenHeight
End Sub
'窗体尺寸改变时
Private Sub Form_Resize()
    Dim i As Integer
    On Error GoTo uerror
    For i = 0 To Controls.Count - 1
        Controls(i).Move ap(i).lp * Me.ScaleWidth, ap(i).tp * Me.ScaleHeight, ap(i).wp * Me.ScaleWidth, ap(i).hp * Me.ScaleHeight
        If Not Me.Controls(i).Name Like "ListView*" Then
            Controls(i).Font.Size = ap(i).fp * (Controls(i).Width * Controls(i).Height)
        End If
    Next i
    Exit Sub
uerror:
    Resume Next
End Sub

转自CSDN

打赏
收藏
点赞
分享到:

温 馨 提 示

  • 付款后看不到下载链接;网盘链接失效;

  • 清零软件无法使用;下载文件不对;

  • 版权侵权,收到后第一时间删除

  • 评论反馈或留言反馈;

  • 退款补发,100M内文件可以发邮件。

  • 可以直接加QQ158695710

  • 邮箱:awwoffice@qq.com158695710@qq.com

    爱普生清零软件步骤视频



标签:VB窗体初始最大化改变窗体大小自动缩放控件字体


欢迎 发表评论:

电脑网络维修排行
  • 随机文章

  • 热评文章

  • 热门文章

网站分类
标签列表

 
QQ在线咨询
客服QQ
158695710
客服邮箱
aww255@qq.com