private static void SizeCaption(InputForm currForm, string caption) { // Work out how big the text will be. SizeF layoutSize = new SizeF (currForm.lblCaption.Width, SystemInformation.WorkingArea.Height); System.Drawing.Graphics grph = System.Drawing.Graphics.FromHwnd(currForm.Handle); SizeF stringSize = grph.MeasureString(caption, currForm.lblCaption.Font, layoutSize); // Resize the caption label and other controls appropriately. if ( ((int) stringSize.Height) > currForm.lblCaption.Height) { currForm.SuspendLayout(); currForm.lblCaption.Height = ((int) stringSize.Height) + 4; currForm.txtInput.Top = currForm.lblCaption.Bottom + 12; currForm.btnCancel.Top = currForm.txtInput.Bottom + 8; currForm.btnOK.Top = currForm.btnCancel.Top; currForm.Height = currForm.btnOK.Bottom + (30); currForm.ResumeLayout(true); } }
private static void SizeCaption(InputForm currForm, string caption) { // Work out how big the text will be. SizeF layoutSize = new SizeF(currForm.lblCaption.Width, SystemInformation.WorkingArea.Height); System.Drawing.Graphics grph = System.Drawing.Graphics.FromHwnd(currForm.Handle); SizeF stringSize = grph.MeasureString(caption, currForm.lblCaption.Font, layoutSize); // Resize the caption label and other controls appropriately. if (((int)stringSize.Height) > currForm.lblCaption.Height) { currForm.SuspendLayout(); currForm.lblCaption.Height = ((int)stringSize.Height) + 4; currForm.txtInput.Top = currForm.lblCaption.Bottom + 12; currForm.btnCancel.Top = currForm.txtInput.Bottom + 8; currForm.btnOK.Top = currForm.btnCancel.Top; currForm.Height = currForm.btnOK.Bottom + (30); currForm.ResumeLayout(true); } }