ListView不在Windows窗体中滚动

时间:2018-06-04 18:12:10

标签: c# listview windows-forms-designer

我正在创建一个带有listview的窗体。列表视图包含多个按钮。但是listview只显示了其中一些。如何使listview可滚动,以便我可以看到所有按钮。这是我的代码

private void checkProgress_Load(object sender, EventArgs e)
        {

        int totalRows = 5;
        int totalCols = 5;

        listView1.View = View.Details;
        listView1.HeaderStyle = ColumnHeaderStyle.None;
        int startX = 0;
        int startY = 0;

        //creating the buttons
        for(int i = 0; i < totalRows; i++)
        {
            for(int j = 0; j < totalCols; j++)
            {
                Button b = new Button();
                b.Location = new System.Drawing.Point(startX, startY);
                b.Size = new System.Drawing.Size(20, 20);
                b.Name = "r" + i + "c" + j;
                startX += 20;
                this.listView1.Controls.Add(b);
            }
            startX = 0;
            startY += 400;

        }            
           //Dummy column
            ColumnHeader header = new ColumnHeader();
            header.Text = "";
            header.Name = "col1";
            listView1.Columns.Add(header);
    }

此代码写在windows窗体的加载函数中。

0 个答案:

没有答案