VB实现界面组件动态分割

在这里插入图片描述
Form上添加一个PictureBox和两个TextBox控件,属性为默认,代码如下:
Option Explicit
Dim X1 As Long '记录鼠标弹起状态经过Picture1获得其X值
Dim L As Long '记录Picture1的Left值
Dim W As Long '记录Text2的宽度
Dim Apsty As Long '设定左边与右边限定距离

Private Sub Form_Load()
Me.AutoRedraw = True: Me.ScaleMode = 3
Picture1.Move Me.ScaleWidth / 2, 0, 8, Me.ScaleHeight
Picture1.BorderStyle = 0
Text1.Move 0, 0, Picture1.Left, Me.ScaleHeight '初始化Text1的位置
Text2.Move Picture1.Left + Picture1.Width, Me.ScaleWidth - Text2.Left, Me.ScaleHeight '初始化Text2的位置
L = Picture1.Left '获取Picture1的Left值到变量L
W = Text2.Width '获取Text2的宽度到变量W
Apsty = IIf(Me.ScaleMode <> vbPixels, 50 * 15, 50)
End Sub

Private Sub Form_Resize()
If Me.ScaleWidth < L + W Then
Picture1.Move IIf(Me.ScaleWidth - W < Apsty, Apsty, Me.ScaleWidth - W)
Text1.Move 0, 0, Picture1.Left
Text2.Move Picture1.Left + Picture1.Width, 0, Me.ScaleWidth - (Picture1.Left + Picture1.Width)
Else
Text2.Move Picture1.Left + Picture1.Width, 0, Me.ScaleWidth - (Picture1.Left + Picture1.Width)
End If
Picture1.Height = Me.ScaleHeight
Text1.Height = Me.ScaleHeight
Text2.Height = Me.ScaleHeight
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.MousePointer = 9
If Button = 1 Then
If Picture1.Left + X - X1 > Apsty And Picture1.Left + X - X1 < Me.ScaleWidth - Apsty Then
Picture1.Move Picture1.Left + (X - X1), 0
End If
Else
X1 = X
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Move 0, 0, Picture1.Left
Text2.Move Picture1.Left + Picture1.Width, 0, Me.ScaleWidth - (Picture1.Left + Picture1.Width)
L = Picture1.Left
W = Text2.Width
End Sub

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

键盘上的舞指

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值