首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 如何使VB程序窗口自适应不同分辨率的屏幕
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-07 18:32:45 楼主
    如何使VB程序窗口自适应不同分辨率的屏幕
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-07 18:56:211楼 得分:0
    放在 Form_Load
    Me.WindowState = 2
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Sandrer
    • 等级:
    发表于:2008-05-07 18:56:322楼 得分:0
    VB.NET code
    Private Sub Form_Load() Me.Move 0, 0, Screen.Width, Screen.Height 'Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 设置窗体居中 End Sub
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 00:32:143楼 得分:0
    这样才更加像自动适应吧,呵呵
    VB.NET code
    Dim SW As Long, SH As Long Private Sub Form_Load() SW = Screen.Width SH = Screen.Height Me.Move 0, 0, SW, SH Timer1.Interval = 500 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() If SW <> Screen.Width And SH <> Screen.Height Then SW = Screen.Width SH = Screen.Height Me.Move 0, 0, SW, SH End If End Sub
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 06:58:544楼 得分:0
    楼上的夸张了点吧
    试试子类化 WM_DISPLAYCHANGE
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 09:21:425楼 得分:0
    窗体最大化就可以了。
    上面直接扩大到屏幕大小的几位,任务条呢?以及其它的工具条呢?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 09:35:096楼 得分:0
    引用 5 楼 Tiger_Zhao 的回复:
    窗体最大化就可以了。
    上面直接扩大到屏幕大小的几位,任务条呢?以及其它的工具条呢?

    Ding.....

    但真正的要适应,窗体的布局问题只有楼主自己考虑了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 11:29:017楼 得分:0
    引用 3 楼 SupermanKing 的回复:
    这样才更加像自动适应吧,呵呵

    VB.NET codeDim SW As Long, SH As Long
    Private Sub Form_Load()
      SW = Screen.Width
      SH = Screen.Height
      Me.Move 0, 0, SW, SH
      Timer1.Interval = 500
      Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Timer()
      If SW <> Screen.Width And SH <> Screen.Height Then
          SW = Screen.Width
          SH = Screen.Height
          Me.Move 0, 0, SW, SH
      End…


    这个有点太夸张了,呵呵,timer来的话不仅会造成系统资源的浪费,还会造成窗体不停闪动
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 12:00:298楼 得分:0
    在form_size里自己设置。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-08 12:46:029楼 得分:0
    最好的办法是用SysInfo控件,这个比较精确.
    然后,窗体上的其他所有控件都跟着居中.也可以自己调整!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-10 22:06:3910楼 得分:0
    谁有现成的摸块最好,因为自己写的话,还要考虑到每一个控件的字体大小,图片大小
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-10 22:57:2311楼 得分:0
    VB.NET code
    Option Explicit Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long ' if True, also fonts are resized '是否缩放字体 Public ResizeFont As Boolean ' if True, form's height/width ratio is preserved '是否保持比例 Public KeepRatio As Boolean Private Type TcontrolInfo ctrl As Control Left As Single Top As Single Width As Single Height As Single FontSize As Single End Type ' this array holds the original position ' and size of all controls on parent form '保存父窗体内所有控件的初始位置与大小 Dim Controls() As TcontrolInfo ' a reference to the parent form '父窗体事件 Private WithEvents ParentForm As Form ' parent form's size at load time '载入时父窗体的大小 Private ParentWidth As Single Private ParentHeight As Single ' ratio of original height/width '初始高宽比例 Private HeightWidthRatio As Single Private Sub ParentForm_Load() ' the ParentWidth variable works as a flag ParentWidth = 0 ' save original ratio '保存初始比例 HeightWidthRatio = ParentForm.Height / ParentForm.Width End Sub Private Sub UserControl_ReadProperties(PropBag As PropertyBag) ResizeFont = PropBag.ReadProperty("ResizeFont", False) KeepRatio = PropBag.ReadProperty("KeepRatio", False) If Ambient.UserMode = False Then Exit Sub ' store a reference to the parent form and ' start receiving events Set ParentForm = Parent End Sub Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "ResizeFont", ResizeFont, False PropBag.WriteProperty "KeepRatio", KeepRatio, False End Sub Private Sub UserControl_Resize() ' refuse to resize '限制大小 Size 420, 420 End Sub ' trap the parent form's Resize event ' this include the very first resize event ' that occurs soon after form's load Private Sub ParentForm_Resize() 'MsgBox "A" LockWindowUpdate ParentForm.hwnd If ParentWidth = 0 Then Rebuild Else Refresh End If LockWindowUpdate 0 'MsgBox "B" End Sub ' save size and position of all controls on parent form ' you should manually invoke this method each time you ' add a new control to the form ' (through Load method of a control array) ' Sub Rebuild() ' rebuild the internal table Dim I As Integer, ctrl As Control ' this is necessary for controls that don't support ' all properties (e.g. Timer controls) On Error Resume Next If Ambient.UserMode = False Then Exit Sub ' save a reference to the parent form ' and its initial size Set ParentForm = UserControl.Parent ParentWidth = ParentForm.ScaleWidth ParentHeight = ParentForm.ScaleHeight ' read the position of all controls on the parent form ReDim Controls(ParentForm.Controls.count - 1) As TcontrolInfo For I = 0 To ParentForm.Controls.count With Controls(I) Set .ctrl = ParentForm.Controls(I) .Left = ParentForm.Controls(I).Left .Top = ParentForm.Controls(I).Top .Width = ParentForm.Controls(I).Width .Height = ParentForm.Controls(I).Height .FontSize = ctrl.Font.Size End With Next End Sub ' update size and position of controls on parent form '更新父窗体内控件的大小与位置 Sub Refresh() Dim I As Integer, ctrl As Control Dim widthFactor As Single, heightFactor As Single Dim minFactor As Single '比例因子 ' inhibits recursive calls if KeepRatio = True Static executing As Boolean If executing Then Exit Sub '如果不是运行时,则退出 If Ambient.UserMode = False Then Exit Sub If KeepRatio Then executing = True ' we must keep original ratio If ParentForm.WindowState <> 2 And ParentForm.WindowState <> 1 Then ParentForm.Height = HeightWidthRatio * ParentForm.Width executing = False End If ' this is necessary for controls that don't support ' all properties (e.g. Timer controls) '错误处理,不能调整所有控件的大小,比如 Timer 控件 On Error Resume Next widthFactor = ParentForm.ScaleWidth / ParentWidth heightFactor = ParentForm.ScaleHeight / ParentHeight ' take the lesser of the two If widthFactor < heightFactor Then minFactor = widthFactor Else minFactor = heightFactor End If ' this is a regular resize For I = 0 To UBound(Controls) With Controls(I) ' the change of font must occur *before* the ' resizing to account for companion scrollbar ' of listbox and other similar controls If ResizeFont Then .ctrl.Font.Size = .FontSize * minFactor End If ' move and resize the controls - we can't use a ' Move method because some controls do not ' support the change of all the four properties ' (eg. Height with comboboxes) '.ctrl.Left = .Left * widthFactor '.ctrl.Top = .Top * heightFactor '.ctrl.Width = .Width * widthFactor '.ctrl.Height = .Height * heightFactor If InStr(UCase(.ctrl.Name), UCase("combo")) <> 0 Then .ctrl.Left = .Left * widthFactor .ctrl.Top = .Top * heightFactor Else .ctrl.Move .Left * widthFactor, .Top * heightFactor, .Width * widthFactor, .Height * heightFactor End If End With Next End Sub

    添加用户控件,代码贴进去

    使用时,工程添加此用户控件,再添加到需要自适应的窗口中即可

    这样都还不会用,可以撞墙了
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-11 12:55:2512楼 得分:0
    我不知道有没有理解错  我个人以为你让控件随着窗体而改变就可以了。
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved