Darkui Darktreeview和Darklistview卷轴问题

发布于 2025-01-17 09:14:01 字数 235 浏览 3 评论 0原文

DarkUI 是适用于 .NET WinForms 的强大黑暗主题控件和对接库 (https://github.com/RobinPerris/DarkUI< /a>)。 尽管如此,DarkTreeView 和 DarkListView 控件在滚动操作上有奇怪的行为。 有人有解决办法吗?

DarkUI is powerful Dark themed control and docking library for .NET WinForms (https://github.com/RobinPerris/DarkUI).
Although, the DarkTreeView and DarkListView controls have strange behaviour on scroll actions.
Does anyone have a solution?

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

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

发布评论

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

评论(1

无需解释 2025-01-24 09:14:02

我已将 UpdateThumb 方法改编为 DarkScrollBar.cs :

private void UpdateThumb(bool forceRefresh = false)
{
    // Calculate size ratio
    float maxsize = (float)((Minimum < Maximum) ? (Maximum - Minimum) : (Maximum - Minimum));
    if (maxsize == 0)
        _viewContentRatio = 1.0f;
    else
        _viewContentRatio = (_scrollOrientation == DarkScrollOrientation.Vertical) ? (Height / maxsize) : (Width / maxsize);
    
    var viewAreaSize = Math.Max(maxsize, 1);
    var positionRatio = ((float)Value - Minimum) / (float)viewAreaSize;
    if (Minimum < 0)
    {
        positionRatio = (float) ((Minimum*-1) + (float) Value)/(float) viewAreaSize;
    }

    // Update area
    if (_scrollOrientation == DarkScrollOrientation.Vertical)
    {
        var thumbSize = (int)(_trackArea.Height * _viewContentRatio);
        _thumbArea = new Rectangle(_trackArea.Left + 3, _trackArea.Top + (int)(_trackArea.Height * positionRatio),
            Consts.ScrollBarSize - 6, Math.Max(thumbSize, Consts.MinimumThumbSize));
    }
    else
    {
        var thumbSize = (int)(_trackArea.Width * _viewContentRatio);
        _thumbArea = new Rectangle(_trackArea.Left + (int)(_trackArea.Width * positionRatio), _trackArea.Top + 3, 
            Math.Max(thumbSize, Consts.MinimumThumbSize), Consts.ScrollBarSize - 6);
    }

    if (forceRefresh)
    {
        Invalidate();
        Update();
    }
}

并将 OnMouseWheel 更改为 DarkScrollBase.cs :

protected override void OnMouseWheel(MouseEventArgs e)
{
    base.OnMouseWheel(e);
    const int offset  = 50;
    var horizontal = false;

    if (_hScrollBar.Visible && ModifierKeys == Keys.Control)
        horizontal = true;

    if (_hScrollBar.Visible && !_vScrollBar.Visible)
        horizontal = true;

    if (!horizontal)
    {
        if (e.Delta > 0)
            _vScrollBar.ScrollBy(-offset);
        else if (e.Delta < 0)
            _vScrollBar.ScrollBy(offset);
    }
    else
    {
        if (e.Delta > 0)
            _hScrollBar.ScrollBy(-offset);
        else if (e.Delta < 0)
            _hScrollBar.ScrollBy(offset);
    }
}

您还可以通过更改偏移值来更改滚动速度。

I've adapted the UpdateThumb method into DarkScrollBar.cs to:

private void UpdateThumb(bool forceRefresh = false)
{
    // Calculate size ratio
    float maxsize = (float)((Minimum < Maximum) ? (Maximum - Minimum) : (Maximum - Minimum));
    if (maxsize == 0)
        _viewContentRatio = 1.0f;
    else
        _viewContentRatio = (_scrollOrientation == DarkScrollOrientation.Vertical) ? (Height / maxsize) : (Width / maxsize);
    
    var viewAreaSize = Math.Max(maxsize, 1);
    var positionRatio = ((float)Value - Minimum) / (float)viewAreaSize;
    if (Minimum < 0)
    {
        positionRatio = (float) ((Minimum*-1) + (float) Value)/(float) viewAreaSize;
    }

    // Update area
    if (_scrollOrientation == DarkScrollOrientation.Vertical)
    {
        var thumbSize = (int)(_trackArea.Height * _viewContentRatio);
        _thumbArea = new Rectangle(_trackArea.Left + 3, _trackArea.Top + (int)(_trackArea.Height * positionRatio),
            Consts.ScrollBarSize - 6, Math.Max(thumbSize, Consts.MinimumThumbSize));
    }
    else
    {
        var thumbSize = (int)(_trackArea.Width * _viewContentRatio);
        _thumbArea = new Rectangle(_trackArea.Left + (int)(_trackArea.Width * positionRatio), _trackArea.Top + 3, 
            Math.Max(thumbSize, Consts.MinimumThumbSize), Consts.ScrollBarSize - 6);
    }

    if (forceRefresh)
    {
        Invalidate();
        Update();
    }
}

And changed OnMouseWheel into DarkScrollBase.cs to:

protected override void OnMouseWheel(MouseEventArgs e)
{
    base.OnMouseWheel(e);
    const int offset  = 50;
    var horizontal = false;

    if (_hScrollBar.Visible && ModifierKeys == Keys.Control)
        horizontal = true;

    if (_hScrollBar.Visible && !_vScrollBar.Visible)
        horizontal = true;

    if (!horizontal)
    {
        if (e.Delta > 0)
            _vScrollBar.ScrollBy(-offset);
        else if (e.Delta < 0)
            _vScrollBar.ScrollBy(offset);
    }
    else
    {
        if (e.Delta > 0)
            _hScrollBar.ScrollBy(-offset);
        else if (e.Delta < 0)
            _hScrollBar.ScrollBy(offset);
    }
}

You can also change the scroll speed by changing the offset value.

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