主题:[讨论]窗口内的控件如果因为窗口大小改变被挡住,是否有办法现实滚动条?
anneall
[专家分:0] 发布于 2008-08-15 16:29:00
一普通窗体(可以最大化,最小化,随意拖动改变窗口的大小)内的控件,如果因为改变了窗口的大小而把窗体内的控件遮住的话,有没有办法让窗体的出现滚动条.
一般情况下,是不会出现滚动条的,除非再次手动把窗口拖大,就可以看到控件了!
有没有办法在窗体变小挡住控件的情况下自动显示滚动条呢????
谢谢!
回复列表 (共4个回复)
沙发
snyga [专家分:1480] 发布于 2008-08-16 00:49:00
用mdi吧
板凳
一江秋水 [专家分:9680] 发布于 2008-08-16 09:27:00
我写的这个代码不知能否满足你的要求:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "USER32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "USER32" () As Long
Private Const WM_MOUSEWHEEL = 522
Private Const PM_REMOVE = &H1
Dim bCancel As Boolean
Dim V0 As Integer '窗体 Height 初值
Dim H0 As Integer '窗体 Width 初值
Dim T(4) As Integer '控件 Top 初值
Dim L(4) As Integer '控件 Left 初值
Dim i As Integer
Private Sub Form_Load()
V0 = Me.ScaleHeight: H0 = Me.ScaleWidth
VScrollBar1.Min = V0: HScrollBar1.Min = H0
T(4) = CmdExit.Top: L(4) = CmdExit.Left '按纽左上角坐标
For i = 0 To 3: T(i) = Frame(i).Top: L(i) = Frame(i).Left: Next '各Frame左上角坐标
Me.Show
ProcessMessages
End Sub
Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
WaitMessage '等待消息
If PeekMessage(Message, Me.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) And VScrollBar1.Visible Then '如果使用了鼠标中轮
If Message.wParam < 0 And VScrollBar1.Value - VScrollBar1.SmallChange >= VScrollBar1.Max Then VScrollBar1.Value = VScrollBar1.Value - VScrollBar1.SmallChange '上卷
If Message.wParam > 0 And VScrollBar1.Value + VScrollBar1.SmallChange <= VScrollBar1.Min Then VScrollBar1.Value = VScrollBar1.Value + VScrollBar1.SmallChange '下卷
End If
DoEvents
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub
Private Sub Form_Resize()
VScrollBar1.Visible = IIf(Me.ScaleHeight < V0, True, False)
HScrollBar1.Visible = IIf(Me.ScaleWidth < H0, True, False)
If Me.ScaleHeight > (HScrollBar1.Height) Then
VScrollBar1.Height = Me.ScaleHeight + (HScrollBar1.Visible = True) * HScrollBar1.Height
HScrollBar1.Width = Me.ScaleWidth + (VScrollBar1.Visible = True) * VScrollBar1.Width
VScrollBar1.Left = HScrollBar1.Width
HScrollBar1.Top = VScrollBar1.Height
VScrollBar1.Max = Me.ScaleHeight - HScrollBar1.Height
HScrollBar1.Max = Me.ScaleWidth - VScrollBar1.Width
VScrollBar1.LargeChange = Me.ScaleHeight
HScrollBar1.LargeChange = Me.ScaleWidth
End If
End Sub
Sub VScrollBar1SonProgram()
CmdExit.Top = T(4) + VScrollBar1.Value - V0
For i = 0 To 3: Frame(i).Top = T(i) + VScrollBar1.Value - V0: Next i
End Sub
Sub HScrollBar1SonProgram()
CmdExit.Left = L(4) + HScrollBar1.Value - H0
For i = 0 To 3: Frame(i).Left = L(i) + HScrollBar1.Value - H0: Next i
End Sub
Private Sub VScrollBar1_Change()
VScrollBar1SonProgram
End Sub
Private Sub VScrollBar1_Scroll()
VScrollBar1SonProgram
End Sub
Private Sub HScrollBar1_Change()
HScrollBar1SonProgram
End Sub
Private Sub HScrollBar1_Scroll()
HScrollBar1SonProgram
End Sub
试验说明:
1.添加横滚、竖滚各一个
2.尽量把控件都集中到框架内,我这里是使用了四个框架和一个按纽
3 楼
一江秋水 [专家分:9680] 发布于 2008-08-16 09:28:00
如果你不使用鼠标中轮,可以删除有关API函数和过程
4 楼
anneall [专家分:0] 发布于 2008-08-16 17:14:00
谢谢,测试 一下!!!
我来回复