简体   繁体   English

在tabPage控件中动态垂直滚动

[英]Scroll vertical dynamically in tabPage control

In my relatively simple project I have a two page tabControl. 在我相对简单的项目中,我有一个两页的tabControl。 tabPage2 consists of dynamically created pictureBoxes (thumbnails, pic_XXX). tabPage2由动态创建的pictureBox(缩略图,pic_XXX)组成。 tabPage2 is of fixed size, with AutoScroll enabled. tabPage2具有固定大小,并启用了自动滚动。

On tabPage1, among other things, I can search for a given name (pic_XXX). 在tabPage1上,除其他外,我可以搜索给定名称(pic_XXX)。 When I switch to tabPage2 I'd like it to be scrolled, so the row in which pic_XXX is, is visible. 当我切换到tabPage2时,我希望它可以滚动,因此pic_XXX所在的行是可见的。 Manually scrolling in tabPage2 is working. 手动滚动tabPage2正在工作。

I'm struggling to dynamically scroll tabPage2 to accomplish this. 我正在努力动态滚动tabPage2来完成此任务。 The following solution throws an exception: 以下解决方案引发异常:

Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.refresh()

I run out of ideas!? 我的想法用光了!

So how to scroll the specified child control into view on an auto-scroll enabled control? 那么如何在启用自动滚动的控件上将指定的子控件滚动到视图中呢?

You should use method .ScrollControlIntoView( [Control] ) 您应该使用方法.ScrollControlIntoView([Control])

tabPage2.ScrollControlIntoView(tabPage2.Controls.Item("pic_" & imgNum) )

Source: LarsTech's 资料来源: LarsTech


Answer for your question: 回答您的问题:

Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location 
tabPage2.VerticalScroll.Maximum = tabPage2.Height
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.PerformLayout()

You have to call .PerformLayout() to make the scrolling control update. 您必须调用.PerformLayout()来使滚动控件更新。

Source: UserControl.VerticalScroll.Value not being set 来源: UserControl.VerticalScroll.Value未设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM