【问题标题】:AutoScroll problem when using Left Dock - C# Telerik Winforms使用 Left Dock 时出现 AutoScroll 问题 - C# Telerik Winforms
【发布时间】:2020-02-04 20:10:23
【问题描述】:

这是我的代码:

RadScrollablePanel panel = new RadScrollablePanel() { AutoScroll = true, Dock = DockStyle.Fill};
pnlclp.PanelContainer.Controls.Add(panel);
foreach (var date in dates)
    panel.Controls.Add(new ucDetails() { Dock = DockStyle.Left });

我在RadScrollablePanel 中添加了一些控件,然后将其添加到PanelContainer 中。 一切都很好。如果我在RadScrollablePanel 中添加这么多第一眼看不到的控件,滚动条也会显示出来。

但是如果我在foreach循环中将DockStyle.Left更改为DockStyle.Right,加载控件后,它不会显示滚动条,这很奇怪,我找不到任何理由或解决方案来解决这个问题。

我什至尝试更改RadScrollablePanelRightToLeft 属性。但没有成功:(

有什么建议吗?

【问题讨论】:

    标签: c# winforms telerik


    【解决方案1】:

    根据提供的信息,我准备了一个示例项目来测试 RadScrollablePanel 中的行为。 我已通过创建公共线程将其记录在我们的反馈门户中。您可以通过以下链接跟踪其进度、订阅状态更改并添加您的 cmets:https://feedback.telerik.com/winforms/1453253-radscrollablepanel-missing-scrollbar-when-there-is-no-enough-space-to-display-the-content-controls

    我希望这些信息对您有所帮助。

    【讨论】:

    • 这是一个非常高级的可滚动面板BUG,它的任务是在特定时间显示滚动。然后,当我查看您提供的链接时,它被标记为计划外错误!!!你觉得这样的标签对吗?我应该等多久才能修复?
    • 遇到的问题是标准 WinForms 面板默认行为的直接后果。如果您使用标准面板尝试相同的场景,您最终会遇到相同的问题 - 水平滚动条未显示,即使正在调整表单大小。在设计 RadScrollablePanel 时,我们的团队决定模仿标准 WinForms 面板的行为。不幸的是,RadScrollablePanel 除了其所有功能外,还继承了 Panel 的问题。
    【解决方案2】:

    要解决标准 Microsoft WinForms 面板的这个问题,我可以建议将所有用户控件停靠在左侧,并使用一个空的面板来占据表单左侧的所有可用空间,因此与所有的行为完全相同用户控件停靠在右侧。当表单的大小发生变化时,调整空面板的宽度。下面的代码说明了所描述的方法:

    public partial class Form1 : Form
    {
        UserControl1[] userControls;
        RadScrollablePanel parentPanel;
        Panel spacePanel;
    
        public Form1()
        {
            InitializeComponent();
    
            new Telerik.WinControls.RadControlSpy.RadControlSpyForm().Show();
        }
    
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
    
            this.parentPanel = new RadScrollablePanel();
            this.parentPanel.Dock = DockStyle.Fill;
    
            this.parentPanel.BackColor = Color.Yellow;
    
            this.Controls.Add(this.parentPanel);
            this.parentPanel.AutoScroll = true;
    
            int count = 10;
            this.userControls = new UserControl1[count];
    
            for (int i = 0; i < count; i++)
            {
                this.userControls[i] =
                    new UserControl1()
                    {
                        Dock = DockStyle.Left,
                        BackColor = Color.FromKnownColor((KnownColor)(i + 50))
                    };
    
                this.parentPanel.Controls.Add(this.userControls[i]);
            }
    
            this.spacePanel = new Panel();
            this.spacePanel.Dock = DockStyle.Left;
            this.parentPanel.Controls.Add(this.spacePanel);
        }
    
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
    
            if (this.spacePanel != null)
            {
                int lastPanelWidth = this.parentPanel.Width;
                foreach (Control control in this.parentPanel.PanelContainer.Controls)
                {
                    if (control.Dock == DockStyle.Left && control != this.spacePanel)
                    {
                        lastPanelWidth -= control.Width;
                    }
                }
    
                if (lastPanelWidth < 0)
                {
                    lastPanelWidth = 0;
                }
    
                this.spacePanel.Width = lastPanelWidth;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 2015-12-01
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2021-05-21
      • 2022-10-15
      • 2019-02-23
      相关资源
      最近更新 更多