本文介绍了父控件的滚动条用于子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案


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


这篇关于父控件的滚动条用于子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:41