Reputation: 2025
I want to give user the ability to resize the datagridview like resizing windows.I mean like when mouse goes over edges of a window it changes to a two-sided arrow and you can resize the window.Is it possible in winforms to do this?
Upvotes: 1
Views: 3916
Reputation: 3138
Though I totally agree with Tergiver that a design like this should almost always be rejected, I remember creating something similar long back when the requirement was to show a few images on a form and user wanted to resize the picturebox for some reason. So if its absolutely necessary or academic you can try something like this:
Add the Grid to a panel add a picturebox to the panel, now dock the grid as fill so that it takes up all the panel space and the picturebox floats above the DataGridView, you might need to change the z-index of picture box in case it goes below the grid. Change the Anchor property of the picturebox from Top,Left to Bottom,Right align it perfectly in the bottom right corner over the grid, keep the picturebox as small as possible so that it does not obscure any cell in the grid. Add a gripper image to the picturebox which will be used to drag the entire stuff and set the picturebox's cursor to SizeNWSE. Blend the backcolor and the gripper image of the picturebox well so that it appears to be a part of the grid. Now handle the mouse move event of the picturebox like this:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.panel1.Height = pictureBox1.Top + e.Y;
this.panel1.Width = pictureBox1.Left + e.X;
}
}
Panel1 is the panel in which we have docked the Grid and picturebox1 is the picturebox over the grid.
Upvotes: 2
Reputation: 14517
While possible, it doesn't make sense to do this. Rather you should anchor/dock the DGV such that the user can resize the whole form and the DGV will follow suit.
Here you can find information on how to layout controls in WinForms. http://msdn.microsoft.com/en-us/library/ms951306.aspx
Upvotes: 1