用VB怎样做拆分式窗口??请老师指点!谢谢!

HZN 2001-03-15 07:23:00
我想做一个拆分式窗口!一边是工具窗口一边是操作窗口!
...全文
127 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdd1125 2001-03-15
  • 打赏
  • 举报
回复
其实实现起来很简单,你的vb98\template\controls\Treeview Listview Splitter.frm
就是一个很好的例子,将它加进你的工程中试试吧
playyuer 2001-03-15
  • 打赏
  • 举报
回复
vb中如何进行窗口拆分?api函数是哪个?
http://www.csdn.net/expert/Topic/39910.shtm
playyuer 2001-03-15
  • 打赏
  • 举报
回复
playyuer answer:
原文 http://microinfo.top263.net/Txt/EasyView.txt
例程下载 http://microinfo.top263.net/Zip/EasyView.exe



例2:在 Delphi 提供了 Splitter 控件,轻而易举就实现了窗体界面的分割视图,而在 VB 中要实现这一
功能则要编写大量代码。
可参阅 VB 6 的"树状视图列表视图拆分条"控件集或"VB 应用程序向导 --> 资源管理器样式"代码,
现将其加工移植为 ActiveX Dll 部件:
创建ActiveX Dll(命名为:EasyViews)工程,并在类模块(命名为:SplitView)
添加如下代码:



Option Explicit
Dim mbMoving As Boolean



Const iError = 120
Const iErrorXY = 150
Const SplitterHW = 80



Dim LeftCtl As Control
Dim RightCtl As Control
Dim TopCtl As Control
Dim BottomCtl As Control



Dim WithEvents ImgSplitterH As Image
Dim WithEvents ImgSplitterV As Image



Dim PictureH As PictureBox
Dim PictureV As PictureBox



Dim WithEvents FormX As Form



Dim iMinWidth As Integer
Dim iMinHeight As Integer
Dim iLeftMargin As Integer
Dim iRightMargin As Integer
Dim iTopMargin As Integer
Dim iBottomMargin As Integer



Public Property Get LeftMargin() As Integer
LeftMargin = iLeftMargin
End Property



Public Property Let LeftMargin(ByVal vNewValue As Integer)
iLeftMargin = vNewValue
End Property



Public Property Get RightMargin() As Integer
RightMargin = iRightMargin
End Property



Public Property Let RightMargin(ByVal vNewValue As Integer)
iRightMargin = vNewValue
End Property



Public Property Get TopMargin() As Integer
TopMargin = iTopMargin
End Property



Public Property Let TopMargin(ByVal vNewValue As Integer)
iTopMargin = vNewValue
End Property



Public Property Get BottomMargin() As Integer
BottomMargin = iBottomMargin
End Property
Public Property Let BottomMargin(ByVal vNewValue As Integer)
iBottomMargin = vNewValue
End Property



Public Property Get MinWidth() As Integer
MinWidth = iMinWidth
End Property



Public Property Let MinWidth(ByVal vNewValue As Integer)
iMinWidth = vNewValue
End Property



Public Property Get MinHeight() As Integer
MinHeight = iMinHeight
End Property



Public Property Let MinHeight(ByVal vNewValue As Integer)
iMinHeight = vNewValue
End Property



Private Sub FormX_Load()
Dim temp As String



temp = "DynamicImageH"
On Error GoTo ErrorHandler
FormX.Controls.Add "VB.Image", temp, FormX
On Error GoTo 0
With FormX.Controls.Item(temp)
.Visible = True
End With
Set ImgSplitterH = FormX.Controls.Item(temp)
ImgSplitterH.MousePointer = 7 'ccsizeEW



temp = "DynamicImageV"
On Error GoTo ErrorHandler
FormX.Controls.Add "VB.Image", temp, FormX
On Error GoTo 0
With FormX.Controls.Item(temp)
.Visible = True
End With
Set ImgSplitterV = FormX.Controls.Item(temp)
ImgSplitterV.MousePointer = 9 'cc2sizeNS



temp = "DynamicPictureH"
On Error GoTo ErrorHandler
FormX.Controls.Add "VB.PictureBox", temp, FormX
On Error GoTo 0
Set PictureH = FormX.Controls.Item(temp)
PictureH.BorderStyle = 0
PictureH.BackColor = vbBlack



temp = "DynamicPictureV"
On Error GoTo ErrorHandler
FormX.Controls.Add "VB.PictureBox", temp, FormX
On Error GoTo 0



Set PictureV = FormX.Controls.Item(temp)



PictureV.BorderStyle = 0
PictureV.BackColor = vbBlack
LeftCtl.Move LeftMargin, TopMargin
ImgSplitterV.Move LeftCtl.Left + LeftCtl.Width, LeftCtl.Top, SplitterHW, LeftCtl.Height
RightCtl.Move ImgSplitterV.Left + SplitterHW, LeftCtl.Top
RightCtl.Height = LeftCtl.Height
ImgSplitterH.Move LeftCtl.Left, LeftCtl.Top + LeftCtl.Height, FormX.Width - LeftMargin - RightMargin, SplitterHW
BottomCtl.Move LeftCtl.Left, LeftCtl.Top + LeftCtl.Height + SplitterHW 'LeftCtl.Height



Exit Sub
ErrorHandler:
temp = temp & "X"
Resume
End Sub



Public Sub Create(LeftCtlX As Object, RightCtlX As Object, BottomCtlX As Object)
Set LeftCtl = LeftCtlX
Set RightCtl = RightCtlX
'Set TopCtl = TopCtlX
Set BottomCtl = BottomCtlX
Set FormX = LeftCtlX.Container
FormX_Load
End Sub



Private Sub FormX_Resize()
If FormX.WindowState <> vbMinimized Then
If FormX.Width < LeftMargin + RightMargin + SplitterHW + MinWidth + LeftCtl.Width + iErrorXY Then
FormX.Width = LeftMargin + RightMargin + SplitterHW + MinWidth + LeftCtl.Width + iErrorXY
End If
If FormX.Height < TopMargin + BottomMargin + SplitterHW + MinHeight + LeftCtl.Height + iErrorXY + iErrorXY + iErrorXY + 6 Then
FormX.Height = TopMargin + BottomMargin + SplitterHW + MinHeight + LeftCtl.Height + iErrorXY + iErrorXY + iErrorXY + 6
End If
RightCtl.Width = FormX.Width - LeftCtl.Width - SplitterHW - LeftMargin - RightMargin - iErrorXY
ImgSplitterH.Width = FormX.Width - LeftMargin - RightMargin - iErrorXY
BottomCtl.Width = ImgSplitterH.Width
BottomCtl.Height = FormX.Height - ImgSplitterH.Top - BottomMargin - SplitterHW - 405
End If
End Sub



Private Sub ImgSplitterH_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
With ImgSplitterH
PictureH.Move .Left - 10, .Top, .Width + 30, .Height / 2
End With
PictureH.Visible = True
mbMoving = True
End Sub



Private Sub ImgSplitterH_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
If mbMoving Then
If Y + ImgSplitterH.Top < LeftCtl.Top + MinHeight Then
PictureH.Top = LeftCtl.Top + MinHeight
ElseIf Y + ImgSplitterH.Top > FormX.Height - BottomMargin - SplitterHW - MinHeight - iErrorXY - iErrorXY - iErrorXY Then
PictureH.Top = FormX.Height - BottomMargin - SplitterHW - MinHeight - iErrorXY - iErrorXY - iErrorXY
Else
PictureH.Top = Y + ImgSplitterH.Top
End If
End If
End If
End Sub



Private Sub ImgSplitterH_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
LeftCtl.Height = PictureH.Top - LeftCtl.Top
ImgSplitterV.Height = LeftCtl.Height
RightCtl.Height = LeftCtl.Height
ImgSplitterH.Top = PictureH.Top
BottomCtl.Height = FormX.Height - ImgSplitterH.Top - BottomMargin - SplitterHW - 400 - 5
BottomCtl.Top = PictureH.Top + SplitterHW
PictureH.Visible = False
mbMoving = False
End Sub



Private Sub ImgSplitterV_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PictureV.Visible = True
With ImgSplitterV
PictureV.Move .Left, .Top - 10, .Width \ 2, .Height
End With
mbMoving = True
End Sub



Private Sub ImgSplitterV_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
If mbMoving Then
If X + ImgSplitterV.Left < LeftCtl.Left + MinWidth Then
PictureV.Left = LeftCtl.Left + MinWidth
ElseIf X + ImgSplitterV.Left > FormX.Width - SplitterHW - RightMargin - MinWidth - iErrorXY Then
PictureV.Left = FormX.Width - SplitterHW - RightMargin - MinWidth - iErrorXY
Else
PictureV.Left = X + ImgSplitterV.Left
End If
End If
PictureV.Height = LeftCtl.Height
End If
End Sub



Private Sub ImgSplitterV_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ImgSplitterV.Left = PictureV.Left
LeftCtl.Width = PictureV.Left - LeftCtl.Left
RightCtl.Width = FormX.Width - LeftCtl.Width - SplitterHW - LeftMargin - RightMargin - iErrorXY '- iError - 200
RightCtl.Left = PictureV.Left + SplitterHW
PictureV.Visible = False
mbMoving = False
End Sub



至此该部件创建完成。
接下来创建标准工程,并在窗体上绘制任意三个控件,如: TreeView、ListView、DataGrid,并编写
如下代码测试 EasyViews 部件的类 SplitView:



Option Explicit
Dim x As New EasyViews.SplitView
Private Sub Form_Load()
'...
x.TopMargin = 500 ' Toolbar1.Height + 100
x.LeftMargin = 1000
x.RightMargin = 1000
x.BottomMargin = 500 'StatusBar1.Height
x.MinHeight = 1000
x.MinWidth = 1200
x.Create TreeView1, ListView1, DataGrid1
'...
End Sub

7,763

社区成员

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

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