在VB中怎么实现整个界面的全屏操作呢?(窗体和控件都要按比例变化)
4个回答
展开全部
Private FormOldWidth As Long
'原始宽度
Private FormOldHeight As Long
'原始高度
Private FormOldTop As Long
Private FormOldLeft As Long
'在调用ResizeForm前先调用本函数
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj
On Error GoTo 0
End Sub
'按比例改变表单内各元件的大小,
'在调用ReSizeForm前先调用ReSizeInit函数
Public Sub ResizeForm(FormName As Form)
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / FormOldWidth
'保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight
'保存窗体高度缩放比例
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For i = 0 To 4
'读取控件的原始位置与大小
TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If
'根据控件的原始位置及窗体改变大小
'的比例对控件重新定位与改变大小
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
Next i
Next Obj
On Error GoTo 0
End Sub
Private Sub Command1_Click()
If Command1.Caption = "全屏" Then
FormOldWidth = Me.Width
FormOldHeight = Me.Height
FormOldTop = Me.Top
FormOldLeft = Me.Left
Me.Height = Screen.Height + 450
Me.Width = Screen.Width + 150
Me.Top = -450
Me.Left = -100
Command1.Caption = "还原"
Else
Me.Height = FormOldHeight
Me.Width = FormOldWidth
Me.Top = FormOldTop
Me.Left = FormOldLeft
Command1.Caption = "全屏"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Call ResizeInit(Me) '在装入时必须加入
Command1.Caption = "全屏"
End Sub
Private Sub Form_Resize()
Call ResizeForm(Me) '控件随之改变
End Sub
'原始宽度
Private FormOldHeight As Long
'原始高度
Private FormOldTop As Long
Private FormOldLeft As Long
'在调用ResizeForm前先调用本函数
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj
On Error GoTo 0
End Sub
'按比例改变表单内各元件的大小,
'在调用ReSizeForm前先调用ReSizeInit函数
Public Sub ResizeForm(FormName As Form)
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / FormOldWidth
'保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight
'保存窗体高度缩放比例
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For i = 0 To 4
'读取控件的原始位置与大小
TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If
'根据控件的原始位置及窗体改变大小
'的比例对控件重新定位与改变大小
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
Next i
Next Obj
On Error GoTo 0
End Sub
Private Sub Command1_Click()
If Command1.Caption = "全屏" Then
FormOldWidth = Me.Width
FormOldHeight = Me.Height
FormOldTop = Me.Top
FormOldLeft = Me.Left
Me.Height = Screen.Height + 450
Me.Width = Screen.Width + 150
Me.Top = -450
Me.Left = -100
Command1.Caption = "还原"
Else
Me.Height = FormOldHeight
Me.Width = FormOldWidth
Me.Top = FormOldTop
Me.Left = FormOldLeft
Command1.Caption = "全屏"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Call ResizeInit(Me) '在装入时必须加入
Command1.Caption = "全屏"
End Sub
Private Sub Form_Resize()
Call ResizeForm(Me) '控件随之改变
End Sub
追问
初步程序是可以运行的,不过我在调试过程中,一个form中含有多个控件,此时有界面就没有显示出来,且其中一部分的比例,处理不完全
追答
因为有些控件的大小本来就是不会改变的。恐怕也只能做到这样子了。你可以根据需要调整一些数据。如果把窗体变成大小不可调,仅能全屏和恢复可能就好了。
展开全部
vb.net 直接设置控件的相关属性就可以了。VB6的话就得自己写方法来实现
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一般软件都不会这么做
追问
我见过在VB中有这样实现的,有可能是我描述的不够清楚,请问在VB中用按键控制的全屏操作怎么实现呢?
追答
Private Sub Command1_Click()
Me.WindowState = vbMaximized
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我做出来了,留下邮箱,我发给你
更多追问追答
追问
非常感谢,邮箱是nan507mm@126.com
追答
已发送,请查收
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询