怎样才能让窗体上的所有控件同窗体的大小一样的变化

lovebirdwu 2002-07-24 10:41:13
当窗体在最大化时各个控件排布很好,但是把窗体大小变化后有的控件就看不到啦,怎样才能解决这个问题。谢谢!!
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]

...全文
40 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
heimayi 2002-07-25
  • 打赏
  • 举报
回复
在RESIZE里设置一下它们的关系就行了
例:
Private Sub Form_Resize()
Command1.Height = Form1.Height
Command1.Width = Form1.Width
End Sub
再加上LEFT和TOP属性。。
如果再加上。screen就更好了。。
kuailexq2000 2002-07-25
  • 打赏
  • 举报
回复
在窗体的load 和 ReSize事件中处理控件的坐标就行了 参看上贴
zyl910 2002-07-25
  • 打赏
  • 举报
回复
在窗体的ReSize事件中处理控件的坐标就行了
kuailexq2000 2002-07-25
  • 打赏
  • 举报
回复
??
kuailexq2000 2002-07-25
  • 打赏
  • 举报
回复
Option Explicit

Private Type ControlsProportion
WidthProportion As Single
HeightProportion As Single
TopProportion As Single
LeftProportion As Single
End Type
Private ArrayOfProportion() As ControlsProportion
Private GridCols As New Collection


Public Sub Resize_Initilize(CurrentForm As Form)
Dim Counter As Integer, CTRL As Control, tmpCols() As Single, i As Integer
On Error GoTo ErrHendel
ReDim ArrayOfProportion(0 To CurrentForm.Controls.Count - 1)
For Counter = 0 To CurrentForm.Controls.Count
rNext:
Set CTRL = CurrentForm.Controls(Counter)
With ArrayOfProportion(Counter)

.WidthProportion = CTRL.Width / CurrentForm.ScaleWidth
.HeightProportion = CTRL.Height / CurrentForm.ScaleHeight
.TopProportion = CTRL.Top / CurrentForm.ScaleHeight
.LeftProportion = CTRL.Left / CurrentForm.ScaleWidth
If TypeOf CTRL Is MSFlexGrid Then
ReDim tmpCols(CTRL.Cols - 1)
For i = 0 To CTRL.Cols - 1
tmpCols(i) = CTRL.ColWidth(i) / CurrentForm.ScaleWidth
Next
GridCols.Add tmpCols, CTRL.Name
End If
End With
Next
Exit Sub
ErrHendel:
If Counter < CurrentForm.Controls.Count - 1 Then
Counter = Counter + 1
Resume rNext
End If
End Sub
Public Sub Size_Changed(CurrentForm As Form)
Dim Counter As Integer, CTRL As Control, i As Integer
Dim t As MSFlexGrid
Dim tmpCols() As Single
On Error GoTo ErrHendel
For Counter = 0 To CurrentForm.Controls.Count - 1
rNext:
Set CTRL = CurrentForm.Controls(Counter)
CTRL.Move ArrayOfProportion(Counter).LeftProportion _
* CurrentForm.ScaleWidth, _
ArrayOfProportion(Counter).TopProportion * CurrentForm.ScaleHeight, _
ArrayOfProportion(Counter).WidthProportion * CurrentForm.ScaleWidth, _
ArrayOfProportion(Counter).HeightProportion * CurrentForm.ScaleHeight
If TypeOf CTRL Is MSFlexGrid Then
tmpCols = GridCols(CTRL.Name)
For i = 0 To CTRL.Cols - 1
CTRL.ColWidth(i) = tmpCols(i) * CurrentForm.ScaleWidth
Next
End If
Next

Exit Sub
ErrHendel:
If Counter < CurrentForm.Controls.Count - 1 Then
Counter = Counter + 1
Resume rNext
End If
End Sub

zzhuahua 2002-07-24
  • 打赏
  • 举报
回复
有一个很好用的控件
如果想要给我你的Email!
visualcpu 2002-07-24
  • 打赏
  • 举报
回复
给你一个简单的代码:
Private Sub Form_Resize()
rtfText.Move 100, 100, Me.ScaleWidth - 200, Me.ScaleHeight - 200
rtfText.RightMargin = rtfText.Width - 400
End Sub
kuailexq2000 2002-07-24
  • 打赏
  • 举报
回复
create a class!!
Option Explicit

Private Type ControlsProportion
WidthProportion As Single
HeightProportion As Single
TopProportion As Single
LeftProportion As Single
End Type
Private ArrayOfProportion() As ControlsProportion
Private GridCols As New Collection


Public Sub Resize_Initilize(CurrentForm As Form)
Dim Counter As Integer, CTRL As Control, tmpCols() As Single, i As Integer
On Error GoTo ErrHendel
ReDim ArrayOfProportion(0 To CurrentForm.Controls.Count - 1)
For Counter = 0 To CurrentForm.Controls.Count
rNext:
Set CTRL = CurrentForm.Controls(Counter)
With ArrayOfProportion(Counter)

.WidthProportion = CTRL.Width / CurrentForm.ScaleWidth
.HeightProportion = CTRL.Height / CurrentForm.ScaleHeight
.TopProportion = CTRL.Top / CurrentForm.ScaleHeight
.LeftProportion = CTRL.Left / CurrentForm.ScaleWidth
If TypeOf CTRL Is MSFlexGrid Then
ReDim tmpCols(CTRL.Cols - 1)
For i = 0 To CTRL.Cols - 1
tmpCols(i) = CTRL.ColWidth(i) / CurrentForm.ScaleWidth
Next
GridCols.Add tmpCols, CTRL.Name
End If
End With
Next
Exit Sub
ErrHendel:
If Counter < CurrentForm.Controls.Count - 1 Then
Counter = Counter + 1
Resume rNext
End If
End Sub
Public Sub Size_Changed(CurrentForm As Form)
Dim Counter As Integer, CTRL As Control, i As Integer
Dim t As MSFlexGrid
Dim tmpCols() As Single
On Error GoTo ErrHendel
For Counter = 0 To CurrentForm.Controls.Count - 1
rNext:
Set CTRL = CurrentForm.Controls(Counter)
CTRL.Move ArrayOfProportion(Counter).LeftProportion _
* CurrentForm.ScaleWidth, _
ArrayOfProportion(Counter).TopProportion * CurrentForm.ScaleHeight, _
ArrayOfProportion(Counter).WidthProportion * CurrentForm.ScaleWidth, _
ArrayOfProportion(Counter).HeightProportion * CurrentForm.ScaleHeight
If TypeOf CTRL Is MSFlexGrid Then
tmpCols = GridCols(CTRL.Name)
For i = 0 To CTRL.Cols - 1
CTRL.ColWidth(i) = tmpCols(i) * CurrentForm.ScaleWidth
Next
End If
Next

Exit Sub
ErrHendel:
If Counter < CurrentForm.Controls.Count - 1 Then
Counter = Counter + 1
Resume rNext
End If
End Sub

lily0000000 2002-07-24
  • 打赏
  • 举报
回复
用screenwidth和screenheight两个变量的合适的表达式来控制控件的大小
恶猫 2002-07-24
  • 打赏
  • 举报
回复
除数为0????? 那可是弄成整除了???
那你试试.
current_control.width=current_control * (me.scalewidth\mw)

要不然.你.
current_control.width=current_control * (me.scalewidth*10/mw)/10

这样就不会为0了.

刚才说为0 是说 mw 为0 还是除的结果为0?

如果是mw 为0 .那你在 通用模块里:
dim mw as integer,mh as integer

lovebirdwu 2002-07-24
  • 打赏
  • 举报
回复
明皓大侠,我试了你的方法但它说除数为0。
怎么回事?谢谢
恶猫 2002-07-24
  • 打赏
  • 举报
回复
在form_load事件里,记下
mw=me.scalewidth
mh=me.scaleheight 两个初始变量

在 form_resize()里.用循环,遍历窗体里面的所有控件.
并把当前检查的控件的长设成
current_control.width=current_control * (me.scalewidth/mw)
同理.高度也一样.

这样就可以了.不管窗体多大... 控件会随着比例自己变化.

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧