C#的WinForms:让面板滚动条看不见的 [英] C# WinForms: Make panel scrollbar invisible
问题描述
我有一个 PANEL1
与自动滚屏= TRUE
。我必须让 PANEL1
与 btnUp
和 btnDown
滚动。到目前为止,我做了什么,我问
I have a panel1
with AutoScroll = true
.I have to make panel1
scroll with btnUp
and btnDown
. So far I've made what I was asked for
private void btnUpClicked(Object sender, EventArgs e)
{
if (panel1.VerticalScroll.Value - 55 > 0)
panel1.VerticalScroll.Value -= 55;
else panel1.VerticalScroll.Value = 0;
}
private void btnDownClicked(Object sender, EventArgs e)
{
panel1.VerticalScroll.Value += 55;
}
但现在我需要隐藏滚动条
或使其不可见。我试过
But now I need to hide Scrollbar
or make it invisible. I tried
panel1.VerticalScroll.Visible = false;
,但它不工作。任何想法家伙?
but it doesn't work. Any ideas guys?
推荐答案
好吧,我已经做了这对你的工作示例。所有你所要做的就是改变这取决于您的面板中的所有项目的总大小的最大值。
Ok, I've done the working example of this for you. All you have to do is to change the max value depending on the total size of all the items inside your panel.
表单代码:
public partial class Form1 : Form
{
private int location = 0;
public Form1()
{
InitializeComponent();
// Set position on top of your panel
pnlPanel.AutoScrollPosition = new Point(0, 0);
// Set maximum position of your panel beyond the point your panel items reach.
// You'll have to change this size depending on the total size of items for your case.
pnlPanel.VerticalScroll.Maximum = 280;
}
private void btnUp_Click(object sender, EventArgs e)
{
if (location - 20 > 0)
{
location -= 20;
pnlPanel.VerticalScroll.Value = location;
}
else
{
// If scroll position is below 0 set the position to 0 (MIN)
location = 0;
pnlPanel.AutoScrollPosition = new Point(0, location);
}
}
private void btnDown_Click(object sender, EventArgs e)
{
if (location + 20 < pnlPanel.VerticalScroll.Maximum)
{
location += 20;
pnlPanel.VerticalScroll.Value = location;
}
else
{
// If scroll position is above 280 set the position to 280 (MAX)
location = pnlPanel.VerticalScroll.Maximum;
pnlPanel.AutoScrollPosition = new Point(0, location);
}
}
}
图片例如:
您必须自动滚屏
选项的面板上设置为假。我希望你明白我做了什么,并会得到你的面板上运行你想要的方式。随意问你是否有任何问题。
You have to set AutoScroll
option to False on your panel. I hope you understand what I've done and will get your panel running the way you want. Feel free to ask if you have any questions.
这篇关于C#的WinForms:让面板滚动条看不见的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!