How can I restrict or control the size of my form?

You can restrict the size of a form by setting it’s MaximumSize and MinimumSize properties. This will help you control the maximum and minimum size the form can be resized to. Also note that WindowState property of the form plays a part in how the form can be resized. [C#] //Minimum width = 300, Minimum height= 300 this.MinimumSize = new Size(300, 300); //Maximum width = 800, Maximum height= unlimited this.MaximumSize = new Size(800, int.MaxValue); [VB.NET] ’Minimum width = 300, Minimum height= 300 Me.MinimumSize = New Size(300, 300) ’Maximum width = 800, Maximum height= unlimited Me.MaximumSize = New Size(800, Integer.MaxValue)

How can I ensure that my form will always be on the desktop?

To set or control the location of the form using desktop coordinates, you can use the SetDeskTopLocation property. You can do this by setting the child form’s TopMost to False and setting its Owner property to the Main Form. [C#] this.SetDesktopLocation(1,1); [VB.NET] Me.SetDesktopLocation(1,1)

How can I autosize the rowheights in my datagrid

Here is a solution suggested by Matthew Benedict. It uses reflection to access the protected DataGridRows collection so he can set the row height. public void AutoSizeGrid() { // DataGrid should be bound to a DataTable for this part to // work. int numRows = ((DataTable)gridTasks.DataSource).Rows.Count; Graphics g = Graphics.FromHwnd(gridTasks.Handle); StringFormat sf = new StringFormat(StringFormat.GenericTypographic); SizeF size; // Since DataGridRows[] is not exposed directly by the DataGrid // we use reflection to hack internally to it.. There is actually // a method get_DataGridRows that returns the collection of rows // that is what we are doing here, and casting it to a System.Array MethodInfo mi = gridTasks.GetType().GetMethod(‘get_DataGridRows’, BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); System.Array dgra = (System.Array)mi.Invoke(gridTasks,null); // Convert this to an ArrayList, little bit easier to deal with // that way, plus we can strip out the newrow row. ArrayList DataGridRows = new ArrayList(); foreach (object dgrr in dgra) { if (dgrr.ToString().EndsWith(‘DataGridRelationshipRow’)==true) DataGridRows.Add(dgrr); } // Now loop through all the rows in the grid for (int i = 0; i < numRows; ++i) { // Here we are telling it that the column width is set to // 400.. so size will contain the Height it needs to be. size = g.MeasureString(gridTasks[i,1].ToString(),gridTasks.Font,400,sf); int h = Convert.ToInt32(size.Height); // Little extra cellpadding space h = h + 8; // Now we pick that row out of the DataGridRows[] Array // that we have and set it’s Height property to what we // think it should be. PropertyInfo pi = DataGridRows[i].GetType().GetProperty(‘Height’); pi.SetValue(DataGridRows[i],h,null); // I have read here that after you set the Height in this manner that you should // Call the DataGrid Invalidate() method, but I haven’t seen any prob with not calling it.. } g.Dispose(); }