反转窗口形成垂直滚动条

发布于 2024-11-06 01:26:51 字数 90 浏览 3 评论 0原文

我正在制作一个 winforms 应用程序 c#。垂直滚动条最小值位于顶部,最大值位于底部,向下滚动增加值,反之亦然。有没有办法把它倒过来,让上面的更高,下面的更低。

I'm making a winforms app c#. The vertical scroll bar min value is at the top and max at the bottom, and scrolling down increases the value and vice versa. Is there a way to invert it, so that up is higher and down is lower.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相守太难 2024-11-13 01:26:51

您实际上无法仅通过查看来“看到”滚动条的,因此,换句话说,将 min 放在顶部、将 max 放在底部、然后将其放置在顶部之间没有实际区别只是在访问时反转该值:

private void ScrollBar_Scroll(object sender, ScrollEventArgs e)
{
    // get the value (0 -> 100)
    int value = scrollBar.Value;

    // invert it (100 -> 0)
    value = 100 - value;

    // display it
    someLabel.Text = value.ToString();
}

当然,您也可以重写 VScrollBar 类并添加您自己的“反转值”属性:

public class InvertedScrollBar : VScrollBar
{
    /// <summary>
    /// Gets or sets the "inverted" scrollbar value.
    /// </summary>
    /// <value>The inverted value.</value>
    public int InvertedValue
    {
        get
        {
            int offset = this.Value - this.Minimum;
            return this.Maximum - offset;
        }
        set
        {
            int offset = this.Maximum - value;
            this.Value = this.Minimum + offset;
        }
    }
}

请注意,Maximum 仍然必须更大 配置时大于最小值。

You cannot actually "see" the value of the scroll bar just by looking at it, so, in other words, there is no actual difference between having min at the top, max at the bottom, and then just inverting the value when you access it:

private void ScrollBar_Scroll(object sender, ScrollEventArgs e)
{
    // get the value (0 -> 100)
    int value = scrollBar.Value;

    // invert it (100 -> 0)
    value = 100 - value;

    // display it
    someLabel.Text = value.ToString();
}

Of course, you can also override the VScrollBar class and add your own "inverted value" property:

public class InvertedScrollBar : VScrollBar
{
    /// <summary>
    /// Gets or sets the "inverted" scrollbar value.
    /// </summary>
    /// <value>The inverted value.</value>
    public int InvertedValue
    {
        get
        {
            int offset = this.Value - this.Minimum;
            return this.Maximum - offset;
        }
        set
        {
            int offset = this.Maximum - value;
            this.Value = this.Minimum + offset;
        }
    }
}

Note that Maximum still has to be larger than Minimum when configuring it.

怪我入戏太深 2024-11-13 01:26:51

ScrollBar 的 Value 属性返回的值从 scrollBar.MinimumscrollBar.Maximum -scrollBar.LargeChange

因此,如果滚动条的最小值为 5,最大值为 15,LargeChange(滚动范围的可见部分)为 3,则可能的返回值从 5 到 12。

因此,要反转该值,您可以实际上想要使用:(

scrollBar.Minimum + scrollBar.Maximum - scrollBar.LargeChange - scrollBar.Value

通常您可以将值视为拇指的左边缘或上边缘的位置。上面的公式将为您提供拇指的下边缘。如果您仍然想要上边缘(即从 8 开始的值)到上例中的 15),然后使用:

scrollBar.Minimum + scrollBar.Maximum - scrollBar.Value

The values returned by the Value property of a ScrollBar go from scrollBar.Minimum to scrollBar.Maximum - scrollBar.LargeChange.

Thus if a scroll bar has Minimum of 5, Maximum of 15, and LargeChange (which doubles as the visible portion of the scrolling range) is 3, then the possible return values go from 5 to 12.

So, to invert the value, you actually want to use:

scrollBar.Minimum + scrollBar.Maximum - scrollBar.LargeChange - scrollBar.Value

(Normally you can think of Value as position of the left or top edge of the thumb. The formula above will give you the bottom edge of the thumb. If you still want the top edge (i.e. values going from 8 to 15 in the example above), then use:

scrollBar.Minimum + scrollBar.Maximum - scrollBar.Value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文