在vb.net中如何获取对象在可滚动面板中的位置 [英] in vb.net how do i get the position of an object in a scrollable panel

查看:21
本文介绍了在vb.net中如何获取对象在可滚动面板中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个面板和其中的许多较小的控件。我正在尝试找到每个控件在滚动出屏幕后的位置。基本上,我尝试找出控件是否在父面板的可视区域中。因此,在对象从面板顶部滚动离开后,我会认为它的"top"值为负值,但情况似乎并非如此。面板的可视窗口的顶部不是0。

推荐答案

下面的示例可能适合您。 此示例在您单击按钮时在面板内创建PictureBox。 PictureBox位置由面板滚动位置确定。(PanelXoffsetPanelYoffsetXPosYPos)

Dim PicBoxCount As Short = 0

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


    If PicBoxCount > 5 Then Exit Sub
    '
    ' New Picture Box Define
    Dim PicBoxNew As New PictureBox
    '
    ' Set Panel Property
    Panel1.Size = New Size(300, 350)
    Panel1.AutoScroll = True
    Panel1.BorderStyle = BorderStyle.FixedSingle
    '
    ' Panel Scroolbars offset determine
    Dim PanelXOffset = Panel1.AutoScrollPosition.X
    Dim PanelYOffset = Panel1.AutoScrollPosition.Y
    '
    ' Increase the number of PictureBox
    PicBoxCount += 1
    '
    ' Based on scrollbar state, set new position
    Dim XPos As Short = (50 * PicBoxCount) + PanelXOffset
    Dim YPos As Short = (120 * PicBoxCount) + PanelYOffset

    ' Create new Picture box
    Panel1.Controls.Add(PicBoxNew)
    PicBoxNew.Name = "PicBox_" & CStr(PicBoxCount)
    PicBoxNew.Width = 100
    PicBoxNew.Height = 100
    PicBoxNew.Location = New Point(XPos, YPos)
    PicBoxNew.BorderStyle = BorderStyle.FixedSingle


End Sub

这篇关于在vb.net中如何获取对象在可滚动面板中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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