父控件的滚动条用于子控件

编程入门 行业动态 更新时间:2024-10-03 10:43:02
本文介绍了父控件的滚动条用于子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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! :)

更多推荐

父控件的滚动条用于子控件

本文发布于:2023-11-03 04:27:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   滚动条

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!