vb.控件随窗体大小...

来源:百度知道 编辑:UC知道 时间:2024/06/13 21:35:43
比如,在窗体画一个TextBox ,然后改变窗体大小,使其与窗体一定比例大小(50%)保持在窗体中心...
代码要怎么写呢?
要是SSTab 或者 ComboBox呢?
愿求多种方法...
对了,我现在用6.0
谢谢了,再等等更好的方法!

谢谢"回答者:匿名 2009-6-6 11:16"的代码,
经过调试,当Form很小的时候,TextBox 的Top有一些误差,不知是不是VB本身的问题?

呵^呵...修改"回答者:匿名 2009-6-6 11:16"的代码,解决!!!
Option Explicit

Sub FormSize(Control As Control)

If TypeName(Control) = "ComboBox" Then

Control.Width = ScaleWidth / 2
Control.Move (ScaleWidth - Control.Width) / 2, (ScaleHeight - Control.Height) / 2
Else
Control.Width = ScaleWidth / 2: Control.Height = ScaleHeight / 2
Control.Move (ScaleWidth - Control.Width) / 2, (ScaleHeight - Control.Height) / 2
End If
End Sub

Private Sub form_resize()

FormSize Text1
FormSize Combo1
End Sub

再次感谢...同时也期待新的方法!!!

Sub ToCenter(control As control)
If TypeName(control) = "ComboBox" Then
control.Move ScaleWidth / 4, (ScaleHeight - control.Height) / 2, ScaleWidth / 2
Else
control.Move ScaleWidth / 4, ScaleHeight / 4, ScaleWidth / 2, ScaleHeight / 2
End If

End Sub

Private Sub Form_Resize()
ToCenter Text1
ToCenter Combo1
ToCenter TabStrip1

End Sub

Private Sub Form_Resize()
Text1.Height = Form1.Height / 2
Text1.Width = Form1.Width / 2
Text1.Top = Form1.Height / 4
Text1.Left = Form1.Width / 4
End Sub
其他都一样 只要把text1改成你要的控件的
name就可以了

text的主要设置属性是left,width,top和height.
可以仿照text的属性设置。
Private Sub Form_Resize()
Text1.Left = Form1.Width / 4
Text1.Width = Form1.Width / 2
Text1.Height = Form1.Height / 2
Text1.Top = Form1.Height / 4 '可以用像素的大小,也可以用百分比
’包括加减乘除都是可以的