父控件的滚动条用于子控件 [英] parent control's scrollbar work for a child control
问题描述
我在tablelayoutpanel内部有tablelayoutpanels
I have tablelayoutpanels inside tablelayoutpanel
MainTableLayoutPanel---cell(colId,RowId)
__________________________ ^
| | cell(1,0) <-+-|-colTblLayoutPnl
|__|_______________________| | (AutoScroll=False)
| | | |
cell(0,1) | | cell(1,1) <-+-|-DetailTblLayoutPnl
RowTblLayoutPnl--+> | | | (AutoScroll=True)
| | | |
|__|_______________________|<|--ScrollBar (want this scrollbar scroll only detail & row tablelayoutpanel's details, don't scroll whole Maintablelayoutpanel because column tablelayout should be static like gridview)
我想在整个Maintablelayoutpanel中显示滚动条.但是,使其仅适用于
DetailTblLayoutPnl
请帮忙,如果有解决方案.
谢谢&问候:)
I want to display scrollbar in whole Maintablelayoutpanel. but, make it work for only
DetailTblLayoutPnl
please, help if have solution.
thanks & regards :)
推荐答案
没有简单的方法可以做到这一点.滚动条不能超过其所在窗口的尺寸.因此,滚动条必须是子级的一部分,而不是父级.
我可以看到的一种方法是将子窗口布置成与父级和子级合并高度相同的大小.该孩子将不再是父母的孩子,它将在Panel控件中独自依靠它. 父级"将放置在Panel控件的顶部,覆盖控件的顶部,是滚动条的缩写.
说实话,您的布局违反了Windows用户体验界面指南文档中列出的Windows UI标准.
There''s no easy way to do this. You cannot have a scrollbar exceed the dimensions of the window that it''s in. So, the scrollbar would have to be part of the child, not the parent.
One way I can see of getting this to work would be to lay out the child window so that it is the same size as the combined parent and child height. The child would no longer be a child of the parent, it would stnad on it''s own in a Panel control. The "parent" would be layed acrossed the top of the Panel control, covering the top portion of the control, excep for the scroll bar.
Truthdfully, your layout kind of violates the Windows UI standards layed out in the Windows User Experience Interface Guidelines document.
希望这对像我一样遇到同样困难的人将非常有用. br/> 我已经使用Vscrollbar控件解决了这个问题,
设计视图如下所示,
wish It will be useful to them who have same difficulty Like I have faced.
I have use Vscrollbar control to solve this problem,
design-view is like below,
MainTableLayoutPanel---cell(colId,RowId)
__________________________ ^
| | cell(1,0) <-+-|-colTblLayoutPnl
|__|_______________________| | (AutoScroll=False)
| | | |
cell(0,1) | | cell(1,1) <-+-|-DetailTblLayoutPnl
RowTblLayoutPnl--+> | | | (AutoScroll=False)
| | | |
|__|_______________________|<|--VScrollBar1 (New scrollbar control) (want this scrollbar scroll only detail & row tablelayoutpanel's details, don't scroll whole Maintablelayoutpanel because column tablelayout should be static like gridview)
注释:不要在MainTableLayoutPanel(tlp)的单元格中停靠或锚定(底部,右侧)tlprow,tlpdtl.因为在这种情况下滚动将不起作用.
并设置tlpdtl&的高度tlprow与容器单元格的高度相同.
什么时候可以看到VScrollBar控件?
Note : Don''t Dock or Anchor(Bottom,right) tlprow,tlpdtl inside MainTableLayoutPanel(tlp)''s cells. because scroll will not work in that case.
and set height of tlpdtl & tlprow same as container cell''s height.
when to visible VScrollBar control?
Private Sub tlp_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tlp.SizeChanged
If (tlpDtl.RowCount * DefaultRowHgt) + tlpDtl.RowCount >= VScrollBar1.Size.Height - tlpcol.Height Then
VScrollBar1.Visible = True
Else
VScrollBar1.Visible = False
End If
End Sub
滚动tlpDtl& tlpRow使用代码[注意:它将逐行滚动(使用defaultRowHeight变量实现该目的.)]
Scrolling tlpDtl & tlpRow using code [Note: It will scroll row by row (defaultRowHeight variable is used for achieve that purpose.) ]
Dim scr = 0 'page variable declared for remember scroll's moment (up-downs).
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
Try
If e.NewValue < e.OldValue Then
scr -= 1
ElseIf e.NewValue = e.OldValue Then
Else
scr += 1
End If
If e.NewValue = 0 Then
scr = 0
End If
tlpDtl.AutoScrollPosition = New Point(0, e.NewValue)
tlprow.AutoScrollPosition = New Point(0, e.NewValue)
tlpDtl.VerticalScroll.Value = (scr * DefaultRowHgt) + scr
tlprow.VerticalScroll.Value = (scr * DefaultRowHgt) + scr
tlprow.Invalidate()
tlpDtl.Invalidate()
Catch ex As Exception
End Try
End Sub
当用户旋转鼠标滚轮时,滚动效果将使用此代码
when user will rotate mouse-wheel scrolling effect will applied using this code
Private Sub tlp_MouseWheel(ByVal sender As Object, ByVal e1 As System.Windows.Forms.MouseEventArgs) Handles tlp.MouseWheel
If VScrollBar1.Visible = True Then
Dim NewValue = VScrollBar1.Value
If e1.Delta > 0 And scr > 0 Then
Try
scr -= 1
VScrollBar1.Value = (scr * DefaultRowHgt) + scr
tlpDtl.VerticalScroll.Value = VScrollBar1.Value
tlprow.VerticalScroll.Value = VScrollBar1.Value
If scr = 0 Then
tlpDtl.AutoScrollPosition = New Point(0, 0)
tlprow.AutoScrollPosition = New Point(0, 0)
End If
Catch
End Try
ElseIf e1.Delta < 0 And scr < Math.Floor(VScrollBar1.Maximum / (DefaultRowHgt + 1)) Then
scr += 1
Try
VScrollBar1.Value = (scr * DefaultRowHgt) + scr
tlpDtl.VerticalScroll.Value = VScrollBar1.Value
tlprow.VerticalScroll.Value = VScrollBar1.Value
Catch ex As Exception
End Try
End If
Try
tlprow.Invalidate()
tlpDtl.Invalidate()
Catch ex As Exception
End Try
End If
End Sub
祝您编码愉快!
:)
Happy Coding!
:)
这篇关于父控件的滚动条用于子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!