【问题标题】:Autosize resizes the form to nearly 0,0Autosize 将表单大小调整为接近 0,0
【发布时间】:2014-04-15 18:54:16
【问题描述】:

我在 datagridview 中有一个表单。我将 datagridview 停靠在中心,所以它填满了整个表单。到目前为止,这有效。我有一个静态数量的行,4,我希望表单自动调整大小,这样你就看不到 datagridview 的灰色底部。我试图通过在表单中​​设置 autosize = true 以及增长和收缩来做到这一点。但是当我开始我的表格时,它缩小到接近 0,0。为什么它没有缩小到数据网格视图的最佳大小?

提前谢谢!

【问题讨论】:

    标签: .net vb.net winforms datagridview window-resize


    【解决方案1】:

    您可以尝试执行以下操作来调整表单的高度:

    'calculate the size of the titlebar and border
    Dim formBorderHeight = (Me.Height - Me.ClientRectangle.Height)
    'adjust the height of the form to the height of the datagrid (assumes each row is the same height)
    Me.Height = DataGridView1.ColumnHeadersHeight + (DataGridView1.RowCount * DataGridView1.RowTemplate.Height) + formBorderHeight
    

    如果您在数据网格上显示滚动条,这将不起作用,因此您可能还需要针对这些进行调整

    【讨论】:

    • 没有更简单的方法吗?我只希望我的 datagridview 尽可能小,就像我设置 Autosizecolumnsmode = allCelss 时一样。下面我只想要一个按钮。然后表单应该在不忽略datagridview的情况下尽可能地自动调整大小(看起来他正在忽略它,因为他的大小取决于我放置按钮的位置,但datagrid被忽略了)。这是一个非常简单的布局,停靠、锚定一定有简单的方法?
    • 我不这么认为。不过这很简单——它只有两行代码!
    猜你喜欢
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多