How to resize datagridview control when form resizes

前端 未结 12 1122
终归单人心
终归单人心 2020-12-29 18:30

I found a lot of questions about how to resize the form when a child control resizes, but I\'m trying to do something much simpler (maybe so simple people don\'t even ask it

相关标签:
12条回答
  • 2020-12-29 19:01

    Set the property of your DataGridView:

    Anchor: Top,Left
    AutoSizeColumn: Fill
    Dock: Fill
    
    0 讨论(0)
  • 2020-12-29 19:02

    Unless I am misunderstanding what you are asking you can do this on the properties for your data grid view. You need to set the Anchor property to the sides you want it locked to.

    0 讨论(0)
  • 2020-12-29 19:02

    For me, anchoring works only if I set it to all four sides:

    Anchoring: Top, Bottom, Left, Right

    Setting anchoring just to Left, Bottom moves the whole object when the form is resized in bottom, left side. Setting all four sizes really resizes the object, when parent is resized.

    0 讨论(0)
  • 2020-12-29 19:04

    In your form constructor you could create an event handler like this:

    this.SizeChanged(frm_sizeChanged);
    

    Then create an event handler that resizes the grid appropriately, example:

    private void frm_sizeChanged(object sender, EventArgs e)
    {
         dataGrid.Size = new Size(100, 200);
    }
    

    Replacing those numbers with whatever you'd like.

    0 讨论(0)
  • 2020-12-29 19:05

    Set the anchor property of the control to hook to all sides of the parent - top, bottom, left, and right.

    0 讨论(0)
  • 2020-12-29 19:06

    You have to chose 'Fill' in the Dock property.

    0 讨论(0)
提交回复
热议问题