gpt4 book ai didi

c# - 获取可滚动屏幕的左下角位置

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:18 25 4
gpt4 key购买 nike

描述在 Winform C# 应用程序中创建了一个表单。

  1. 添加了带有停靠类型填充的面板 (PBack)。 (可滚动)

  2. 然后在面板(PBack)中添加一个图片框(pbDraw),高度取决于图像大小。

我想在当前屏幕 View 的左下角添加一个控件。 (假设客户端向下滚动)

我尝试了什么

  1. 矩形 rect = Screen.GetWorkingArea(pbDraw);ctrl.Top = rect.Top + rect.Height;

  2. ctrl.Top = Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height;

  3. ctrl.Top = Screen.FromControl(pbDraw).WorkingArea.Top+ Screen.FromControl(pbDraw).WorkingArea.Height;

问题 控件添加到 pbDraw (0,0) 的顶部而不是当前屏幕边界的顶部。

enter image description here

最佳答案

据我了解,Control.Top单独考虑 ScrollView 。

Gets or sets the distance, in pixels, between the top edge of the control and the top edge of its container's client area.

因此,您应该能够分配与 pBack 及其客户端 View 相关的坐标:

ctrl.Top = pBack.Height - ctrl.Height;

假设 ctrlpBack 的子级,这段代码应该将它放在 pBack 当前(滚动的)部分的底部>/p>

更新:

正如您在评论中所说,ctrl 实际上是 pbDraw 的子项。在这种情况下,您需要考虑滚动。为此,您可以使用 Panel.VerticalScroll :

//scroll position + panel height - control height
ctrl.Top = pBack.VerticalScroll.Value + pBack.Height - ctrl.Height;

如果我是你,我会将 ctrl 添加到图片框顶部的面板。这将使计算相对于面板的偏移量变得更加容易。

关于c# - 获取可滚动屏幕的左下角位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com