我一直在使用UserControl来显示控件列表。我最初启用了AutoScroll
,然后选择不使用它。我选择不使用它,因为它很突出,并且对于我一直使用的控件主题根本不“看起来”不错。
我在名为MetroFramework的框架上拍摄了照片,我选择将MetroScrollBar
滚动条控件用于垂直滚动条。
我完全禁用了AutoScroll,然后决定实现Scrollbar。我只是通过以下方式做到这一点:
scbMain.Scroll += (sender, e) => { VerticalScroll.Value = scbMain.Value; };
(其中scbMain
是我正在讨论的滚动条)
这有效,但不符合预期。滚动后,默认滚动条就会出现疯狂的闪烁效果,如here所示。较长的列表包含the same effect, but more pronounced。
我试图隐藏现有的滚动条:
VerticalScroll.Visible = false;
HorizontalScroll.Visible = false;
VerticalScroll.Enabled = false;
HorizontalScroll.Enabled = false;
这对解决我的问题没有影响。
应注意:我的滚动条停靠在右侧,UserControl
中没有其他容器控件。
答案 0 :(得分:1)
好的。问题解决了。问题出在以下代码行中:
def strchecker(question):
while True:
user_Name = input(question)
if user_Name:
return user_Name # Make sure to capitalize the N in user_Name
break
else:
print("Do no leave username blank")
print("*************Welcome to the Te Reo Maori Quiz***************")
user_Name = strchecker("Please enter your username")
您正在手动设置用户控件的滚动值,基本上是告诉系统调用autoscroll属性来设置该值!
正确的方法是不自动滚动用户控件,而是滚动例如面板内的容器。因此,将面板添加到您的用户控件中。您将滚动面板及其中的所有控件(在本例中,我将添加按钮)。
scbMain.Scroll += (sender, e) => { ----> /*(Here*/ VerticalScroll.Value = scbMain.Value; <---- };
滚动:
this.btnExample.Location = new System.Drawing.Point(62, 0);
this.btnExample.Name = "btnExample";
this.btnExample.Size = new System.Drawing.Size(75, 390);
this.btnExample.TabIndex = 1;
this.btnExample.Text = "Out of Bounds";
this.btnExample.UseVisualStyleBackColor = true;
this.panel1.Controls.Add(this.btnExample);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(270, 391); //the width must fit inside your user control and the height was arbitrary
this.panel1.TabIndex = 2;
this.Controls.Add(this.panel1);
this.Controls.Add(this.scbMain);
this.Name = "CtrlScroll";
this.Size = new System.Drawing.Size(474, 300);