如何滚动面板以使特定控件成为面板的最高位置? [英] How Can I Scroll a Panel So That A Particular Control Is At THE TOP of the Panel?

查看:59
本文介绍了如何滚动面板以使特定控件成为面板的最高位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ScrollControlIntoView将控件置于底部。  (上下文。)


我认为  ScrollToControl提供了面板所具有的点滚动到,但我没有任何这些尝试的运气:


'pnlFromItems.SetDisplayRectLocation(ptTargetLoc.X,ptTargetLoc.Y)

                'pnlFromItems.AutoScrollPosition = ptTargetLoc

                pnlFromItems.AutoScrollOffset = ptTargetLoc


背景信息: 面板中的每个控件代表一个美国州 - 控件采用列表格式。 如果用户输入单个字符,我希望面板滚动,以便状态控件位于面板的顶部。 如果用户以
为例输入一个N,他可能想要几种状态中的任何一种。 如果面板定位自己以便以N开头的第一个状态位于面板的顶部会更有帮助。  


我会感激任何人的帮助可以给我。 谢谢,  Bob



解决方案

我发现在自动滚动到不应该是的控件之前我需要将AutoScrollPosition设置为New Point(0,0)案件真的。作为

Control.AutoScrollOffset属性
说"获取或设置此控件在

ScrollControlIntoView
。"或许我没有正确使用它。无论如何,我在面板上以各种顺序放置了9个按钮,这样大多数都在滚动区域之外,并且不断滚动到Button7。


但是你的要求不仅仅是我不能执行也不让我的项目尝试或想要这样做。但是这段代码每次都会滚动到Button7。虽然它不是在滚动区域的中心而不是您想要的顶部。有
需要你使用的一些补偿来弄清楚如何执行,所以每个控制都可以在中心的顶部,这将难以执行IMO。

 Option Strict On 

Public Class Form1

Private Sub Form1_Load(sender as Object,e As EventArgs)Handles MyBase.Load
Me.Location =新点(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)),CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
Panel1.AutoScroll = True
End Sub

Private Sub Button10_Click(sender As Object,e As EventArgs)处理Button10.Click
Panel1.AutoScrollPosition =新点(0,0)
Panel1.AutoScrollPosition = Button7.Location
End Sub
End Class




ScrollControlIntoView puts the control at the bottom.  (Context below.)

I think that ScrollToControl provides the point that the panel has to scroll to but I've had no luck with any of these attempts:

'pnlFromItems.SetDisplayRectLocation(ptTargetLoc.X, ptTargetLoc.Y)
                'pnlFromItems.AutoScrollPosition = ptTargetLoc
                pnlFromItems.AutoScrollOffset = ptTargetLoc

Context:  Each control in the panel represents a US state - the controls are in a list format.  If the user enters a single character I want the panel to scroll so that the state's control is at the top of the panel.  If the user enters, for example, a N he may want any one of several states.  It would be much more helpful if the panel positioned itself so that the first state beginning with a N was at the top of the panel.  

I'll appreciate any assistance anyone can give me.  Thanks,  Bob

解决方案

I found that I need to set the AutoScrollPosition to New Point(0, 0) before autoscrolling to a control which should not be the case really. As Control.AutoScrollOffset Property says "Gets or sets where this control is scrolled to in ScrollControlIntoView.". Or maybe I'm not using it correctly. Anyhow I put about 9 buttons in various order on the Panel so that most were outside of the scroll area and scrolled to Button7 constantly.

But your requirement is for alot more that I can not perform nor do I have your project to attempt it with or want to do it. But this code scrolls to Button7 everytime. Although it is not centered in the scrolled area and not at the top as you desire. There would need to be some offsets used by you to figure out how to perform that so every control could be at the top in the center which would be difficult to perform IMO.

Option Strict On

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
        Panel1.AutoScroll = True
    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        Panel1.AutoScrollPosition = New Point(0, 0)
        Panel1.AutoScrollPosition = Button7.Location
    End Sub
End Class


这篇关于如何滚动面板以使特定控件成为面板的最高位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆