VB中如何设置窗体内控件大小随窗体大小改变而改变?
5个回答
展开全部
先在Form_Load中记录控件的相对位置及大小比例,然后在Form_Resize中按比例设置控件的位置及大小即可:
Dim ll As Single, tt As Single, ww As Single, hh As Single
Private Sub Form_Load()
ll = Text1.Left / Me.ScaleWidth
tt = Text1.Top / Me.ScaleHeight
ww = Text1.Width / Me.ScaleWidth
hh = Text1.Height / Me.ScaleHeight
End Sub
Private Sub Form_Resize()
Text1.Left = Me.ScaleWidth * ll
Text1.Top = Me.ScaleHeight * tt
Text1.Width = Me.ScaleWidth * ww
Text1.Height = Me.ScaleHeight * hh
End Sub
如果控件比较多的话,就要用数组了。
Dim ll As Single, tt As Single, ww As Single, hh As Single
Private Sub Form_Load()
ll = Text1.Left / Me.ScaleWidth
tt = Text1.Top / Me.ScaleHeight
ww = Text1.Width / Me.ScaleWidth
hh = Text1.Height / Me.ScaleHeight
End Sub
Private Sub Form_Resize()
Text1.Left = Me.ScaleWidth * ll
Text1.Top = Me.ScaleHeight * tt
Text1.Width = Me.ScaleWidth * ww
Text1.Height = Me.ScaleHeight * hh
End Sub
如果控件比较多的话,就要用数组了。
展开全部
先在Form_Load中记录控件的相对位置及大小比例,然后在Form_Resize中按比例设置控件的位置及大小即可:
Dim ll As Single, tt As Single, ww As Single, hh As Single
Private Sub Form_Load()
ll = Text1.Left / Me.ScaleWidth
tt = Text1.Top / Me.ScaleHeight
ww = Text1.Width / Me.ScaleWidth
hh = Text1.Height / Me.ScaleHeight
End Sub
Private Sub Form_Resize()
Text1.Left = Me.ScaleWidth * ll
Text1.Top = Me.ScaleHeight * tt
Text1.Width = Me.ScaleWidth * ww
Text1.Height = Me.ScaleHeight * hh
End Sub
如果控件比较多的话,就要用数组了。
Dim ll As Single, tt As Single, ww As Single, hh As Single
Private Sub Form_Load()
ll = Text1.Left / Me.ScaleWidth
tt = Text1.Top / Me.ScaleHeight
ww = Text1.Width / Me.ScaleWidth
hh = Text1.Height / Me.ScaleHeight
End Sub
Private Sub Form_Resize()
Text1.Left = Me.ScaleWidth * ll
Text1.Top = Me.ScaleHeight * tt
Text1.Width = Me.ScaleWidth * ww
Text1.Height = Me.ScaleHeight * hh
End Sub
如果控件比较多的话,就要用数组了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以抛锚用anchor,不过这种方法只是控制控件的四个边的得相对坐标,控件大小可以随意,如果想完全跟随,实际上是像素坐标是变化的,必须用代码写。。。。其实也简单,让控件坐标和窗口size成比例就行了。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
form有一个resize事件
private
sub
form_resize()
……
end
sub
里面添加窗体大小变化的时候控件的变化就行了。
当然,对于应该如何变化,就得自己先算好咯。
private
sub
form_resize()
……
end
sub
里面添加窗体大小变化的时候控件的变化就行了。
当然,对于应该如何变化,就得自己先算好咯。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1、全用代码控制大小和位置
2、用乘除法,不用加减
3、在Form_Resize里面写代码
比如
Private Sub Form_Resize()
Command1.Width = 0.2 * Me.Width
Command1.Height = 0.2 * Me.Height
Command1.Top = 0.15 * Me.Height
Command1.Left = 0.3 * Me.Height
End Sub
2、用乘除法,不用加减
3、在Form_Resize里面写代码
比如
Private Sub Form_Resize()
Command1.Width = 0.2 * Me.Width
Command1.Height = 0.2 * Me.Height
Command1.Top = 0.15 * Me.Height
Command1.Left = 0.3 * Me.Height
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询