菜鸟问题

pzhuzgx 2003-12-18 05:48:29


如何实现窗体的分割

就象网页的框架一样。
分成左右两边。


...全文
87 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mars.CN 2003-12-21
picturebox
回复
3661512 2003-12-18
就是所说的分割线窗体
具体实现方法.新建一个工程,在窗体上放一个treeview(lstPers)和一个listview(lstTel),还有一个picturebox(Splitter),摄制PictrueBox的MousePointer属性为9,括号里代表为该控件取的名称.
然后在窗体写入如下代码:
Option Explicit
'定义需要使用的变量
Private Const P_ECART = 3
Private x1 As Integer, x2 As Integer
Private y1 As Integer, y2 As Integer
Private width1 As Integer, width2 As Integer
Private height1 As Integer, height2 As Integer
Private glbfrmInSizeX As Long

'初始化窗体和变量
Private Sub Form_Load()
glbfrmInSizeX = &H7FFFFFFF
Form_Resize
End Sub

'当鼠标按下切分条Splitter的时候
Private Sub splitter_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
'如果是鼠标左键按下,设置切分条颜色,并将鼠标坐标值付给变量glbfrmInSizeX
Splitter.BackColor = &H808080
glbfrmInSizeX = CLng(x)
Else
If glbfrmInSizeX <> &H7FFFFFFF Then
'如果是鼠标右键按下,即认为是松开切分条
splitter_MouseUp Button, Shift, x, y
End If
glbfrmInSizeX = &H7FFFFFFF
End If

End Sub

'当切分条Splitter移动的时候
Private Sub splitter_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If glbfrmInSizeX <> &H7FFFFFFF Then
If CLng(x) <> glbfrmInSizeX Then
'将切分条的坐标,按鼠标位置移动
Splitter.Move Splitter.Left + x, y1, P_ECART, ScaleHeight - 2
glbfrmInSizeX = CLng(x)
End If
End If
End Sub

'当鼠标松开切分条Splitter的时候
Private Sub splitter_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If glbfrmInSizeX <> &H7FFFFFFF Then
If CLng(x) <> glbfrmInSizeX Then
Splitter.Move Splitter.Left + x, y1, P_ECART, ScaleHeight - 2
End If
glbfrmInSizeX = &H7FFFFFFF
Splitter.BackColor = &H8000000F
'判断切分条有没有出窗体边界,另切分条不能移出窗体边界
If Splitter.Left > 60 And Splitter.Left < (ScaleWidth - 60) Then
lstPers.Width = Splitter.Left - lstPers.Left
ElseIf Splitter.Left < 60 Then
lstPers.Width = 60
Else
lstPers.Width = ScaleWidth - 60
End If
Form_Resize
End If
End Sub



'窗体的大小改变
Private Sub Form_Resize()
Const B_ECART = 1
On Error Resume Next
'赋值
y1 = B_ECART
height1 = ScaleHeight - B_ECART * 2
x1 = B_ECART
width1 = lstPers.Width
x2 = x1 + lstPers.Width + P_ECART - 1
width2 = ScaleWidth - x2 - B_ECART
'调整ListBox和Splitter适应位置
lstPers.Move x1 - 1, y1, width1, height1
lstTel.Move x2, y1, width2 + 1, height1
Splitter.Move x1 + lstPers.Width - 1, y1, P_ECART, height1
End Sub

如果还有什么问题,留下信箱,我给你发个分割线窗体的代码.
回复
betagain 2003-12-18
网上有vb源代码
回复
danielinbiti 2003-12-18
一个picturebox
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告