一个困了我好久的窗体分布问题

yingxiangchen 2004-11-03 07:03:29
如果想让MDI窗体内的子窗体象VB环境中的工具窗体及属性和窗体列表窗体一样固定其位置,让其它子窗体即使最大化,也只能拥有固定窗体占有后剩下的空间,要怎么写呢,多谢高手指点!!在线等高手回复!!
...全文
109 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
_TMG_ 2004-11-05
  • 打赏
  • 举报
回复
根本无法看懂, 那么多控件没有描述, 能否提供下载, 或者 frmMain.frm 和 frmDock.frm 的所有内容贴上来
yingxiangchen 2004-11-05
  • 打赏
  • 举报
回复
有两个窗体,一个为frmMain,另一个为frmDock
frmMain的Code
Option Explicit
Private Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hwnd&, ByVal HelpFile$, ByVal wCommand%, dwData As Any)

Private Sub Form_Load()
Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
Show
frmDock.Show , Me
End Sub


Private Sub Form_Unload(Cancel As Integer)
End
End Sub

Private Sub picHolder_Paint()
picTitle.Width = picHolder.ScaleWidth
picSizer.Visible = picHolder.Align > 0

frmDock.picContents.Width = picHolder.ScaleWidth
frmDock.picContents.Height = picHolder.ScaleHeight
frmDock.picContents_Resize
End Sub

Private Sub picSizer_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Dim nSide As Integer
If picHolder.Visible Then
'// need to do this or SendMessage fails
ReleaseCapture
'// Send message to start resizing frmDocking.Picture1
Select Case picSizer.Align
Case vbAlignRight
nSide = HTLEFT
Case vbAlignLeft
nSide = HTRIGHT
Case vbAlignTop
nSide = HTBOTTOM
Case vbAlignBottom
nSide = HTTOP
End Select
SendMessage picHolder.hwnd, WM_NCLBUTTONDOWN, nSide, ByVal &O0
If picHolder.Width < 500 Then picHolder.Width = 500
If picHolder.Height < 500 Then picHolder.Height = 500
picHolder_Resize
End If
Else

End If

End Sub

Private Sub picSizer_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If picSizer.Width > picSizer.Height Then
picSizer.MousePointer = 7
Else
picSizer.MousePointer = 9
End If

End Sub

Private Sub picSizer_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
picSizer.BackColor = &H8000000A
Call frmDock.picContents_Resize
End Sub

Private Sub picTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > frmDock.picTitle.Width Then X = frmDock.picTitle.Width \ 2
firstDown.X = X
firstDown.Y = Y

End Sub

Private Sub picTitle_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
'SendMessage frmDock.picTitle.hwnd, WM_LBUTTONDOWN, 0, 0
frmDock.picTitle_MouseMove 1, Shift, X, Y
End Sub

Private Sub picTitle_Paint()
picTitle.Cls
picTitle.Print "Teste"
End Sub

Private Sub picHolder_Resize()
picTitle.Width = picHolder.ScaleWidth
picSizer.Visible = picHolder.Align > 0

frmDock.picContents.Width = picHolder.ScaleWidth
frmDock.picContents.Height = picHolder.ScaleHeight
frmDock.picContents_Resize
End Sub


frmDock的Code

Public Sub Form_Resize()
picContents.Height = Me.Height - picTitle.Height - 50
picContents.Width = Width
End Sub

Public Sub picContents_Resize()
'File1.Move 0, 0, picContents.Width, picContents.Height - 200
' File1.Width = picContents.Width
' File1.Height = picContents.Height
If GetParent(picContents.hwnd) = Me.hwnd Then
File1.Width = picContents.Width - 100
File1.Height = picContents.Height
Else
File1.Width = picContents.Width
File1.Height = picContents.Height - 500
End If
End Sub

Private Sub picTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
firstDown.X = X
firstDown.Y = Y
End Sub

Public Sub picTitle_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Dim pp As POINTAPI
GetCursorPos pp
pp.Y = pp.Y * Screen.TwipsPerPixelY
pp.X = pp.X * Screen.TwipsPerPixelX
Me.Top = pp.Y - firstDown.Y
Me.Left = pp.X - firstDown.X
'fMainForm.picHolder.Width = Me.Width
Dim tmp
If (pp.Y > fMainForm.Top And _
pp.Y < fMainForm.Top + fMainForm.picSnap.Height And _
pp.X > fMainForm.Left And pp.X < fMainForm.Left _
+ fMainForm.Width) And (Shift <> vbCtrlMask) Then


fMainForm.picHolder.Align = vbAlignTop
' fMainForm.picHolder.Width = fMainForm.Width
fMainForm.picHolder.Height = Me.Height
'
fMainForm.picHolder.Visible = True
Me.Visible = False
If GetParent(picContents.hwnd) <> fMainForm.picHolder.hwnd Then _
SetParent picContents.hwnd, fMainForm.picHolder.hwnd
ElseIf (pp.Y > fMainForm.Top + fMainForm.Height - fMainForm.picSnap.ScaleHeight And _
pp.Y < fMainForm.Top + fMainForm.Height And _
pp.X > fMainForm.Left And pp.X < fMainForm.Left _
+ fMainForm.Width) And (Shift <> vbCtrlMask) Then


fMainForm.picHolder.Align = vbAlignBottom
' fMainForm.picHolder.Width = fMainForm.Width
fMainForm.picHolder.Height = Me.Height
'
fMainForm.picHolder.Visible = True
Me.Visible = False
If GetParent(picContents.hwnd) <> fMainForm.picHolder.hwnd Then _
SetParent picContents.hwnd, fMainForm.picHolder.hwnd
ElseIf (pp.Y > fMainForm.Top And pp.Y < fMainForm.Top + fMainForm.Height And pp.X > fMainForm.Left And pp.X < fMainForm.Left + fMainForm.picSnap.Width) And (Shift <> vbCtrlMask) Then
fMainForm.picHolder.Align = vbAlignLeft
fMainForm.picHolder.Width = Me.Width
' fMainForm.picHolder.Height = Me.Height
fMainForm.picHolder.Visible = True
Me.Visible = False
If GetParent(picContents.hwnd) <> fMainForm.picHolder.hwnd Then _
SetParent picContents.hwnd, fMainForm.picHolder.hwnd

ElseIf (pp.Y > fMainForm.Top And pp.Y < fMainForm.Top + fMainForm.Height And pp.X > fMainForm.Left + fMainForm.Width - fMainForm.picSnap.Width And pp.X < fMainForm.Left + fMainForm.Width) And (Shift <> vbCtrlMask) Then
fMainForm.picHolder.Align = vbAlignRight
fMainForm.picHolder.Width = Me.Width
' fMainForm.picHolder.Height = Me.Height
fMainForm.picHolder.Visible = True
Me.Visible = False
If GetParent(picContents.hwnd) <> fMainForm.picHolder.hwnd Then _
SetParent picContents.hwnd, fMainForm.picHolder.hwnd


Else
fMainForm.picHolder.Visible = False
Visible = True
If GetParent(picContents.hwnd) <> Me.hwnd Then _
SetParent picContents.hwnd, Me.hwnd
End If
picContents.Refresh
picTitle_Paint
fMainForm.picSizer.Align = 0
fMainForm.picSizer.Align = fMainForm.picHolder.Align
Select Case fMainForm.picSizer.Align
Case vbAlignTop, vbAlignBottom
fMainForm.picSizer.Height = 80
Case vbAlignRight, vbAlignLeft
fMainForm.picSizer.Width = 80
End Select
If GetParent(picContents.hwnd) = Me.hwnd Then

picContents.Height = Me.Height - picTitle.Height - 50
picContents.Width = Width
End If
End Sub

Private Sub picTitle_Paint()
picTitle.Cls
picTitle.Print "Teste"
End Sub
yingxiangchen 2004-11-04
  • 打赏
  • 举报
回复
明天吧,今天好晚了,我要睡了,明天我贴给各位看看吧,多指教
_TMG_ 2004-11-04
  • 打赏
  • 举报
回复
介绍一下啊, 晕
yingxiangchen 2004-11-04
  • 打赏
  • 举报
回复
我已经找到了解决的方法,谢谢各位的支持!! 写出来的介面还蛮Cool的。呵呵
yingxiangchen 2004-11-03
  • 打赏
  • 举报
回复
我是想要让窗体确实是最大化了WindowState=vbMaximized,但显示的空间确有所限制,在这之前还有一个最重要的是怎样固定窗体,让其自动在规定的位置,就象VB开发环境一样,工具窗体的位置只要被拉到边沿,就会自动固定到左边,VB可以做到这个吗?
a达哥a 2004-11-03
  • 打赏
  • 举报
回复
用FORM_RESIZE()事件, 实时控制子窗体的大小, 当判断到子窗体被最大化的时候, 转为正常模式, 把子窗体的Height和Width属性变化为需要的大小, 如:
Private sub Form_Resize()
if me.WindowState=vbMaximized then
me.WindowState=vbNormal
me.move 0,100,800,400 ''这个句子就是改变你的窗体为固定大小的!
endif
End Sub

starsoulxp 2004-11-03
  • 打赏
  • 举报
回复
up

7,763

社区成员

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

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