C# WinForms:使面板滚动条不可见 [英] C# WinForms: Make panel scrollbar invisible

查看:28
本文介绍了C# WinForms:使面板滚动条不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 AutoScroll = truepanel1.我必须使用 btnUppanel1 滚动代码>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;
}

但现在我需要隐藏 Scrollbar 或使其不可见.我试过

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);
        }
    }
}

<小时>

图片示例:

您必须在面板上将 AutoScroll 选项设置为 False.我希望你理解我所做的,并让你的面板按你想要的方式运行.如果您有任何问题,请随时提问.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆