How to scroll in flowlayout panel without showing scrollbar in windows form

喜夏-厌秋 提交于 2019-12-01 21:29:49

问题


I am working on a touch screen POS in WinForms.

I have a flowlayoutpanel and add buttons dynamically but I dont want to show a scrollbar.

I use 2 buttons to scroll instead, so please help me how to scroll without showing a scrollbar


回答1:


Take two buttons btnLeft and btnRight and try this code :

private void btnLeft_Click(object sender, EventArgs e)
{
    if (flowPanelItemCategory.Location.X <= xpos)
    {
        xmin = flowPanelItemCategory.HorizontalScroll.Minimum;
        if (flowPanelItemCategory.Location.X >= xmin)
        {
            xpos -= 100;
            flowPanelItemCategory.Location = new Point(xpos, 0);
        }
    }
}

private void btnRight_Click(object sender, EventArgs e)
{
    if (flowPanelItemCategory.Location.X <= xpos)
    {
        xmax = flowPanelItemCategory.HorizontalScroll.Maximum;
        if (flowPanelItemCategory.Location.X < xmax)
        {
            xpos += 100;
            flowPanelItemCategory.Location = new Point(xpos, 0);
        }
    }
}



回答2:


Try placing the FlowLayoutPanel inside another panel with these properties:

flowLayoutPanel1.AutoScroll = false;
flowLayoutPanel1.AutoSize = true;
flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;

From here, you have to control yourself the location of the FlowLayoutPanel1 inside your panel (which should also have AutoScroll = false;) based on your two buttons.



来源:https://stackoverflow.com/questions/10980771/how-to-scroll-in-flowlayout-panel-without-showing-scrollbar-in-windows-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!