Form height and width measured differently than TextBox height

Home / Uncategorized / Form height and width measured differently than TextBox height

Question:
I’m using a function to create textboxes for a class for making arrays of textboxes, and I want to center the grid to the form. After some debugging, I realized that the form height and width are measured on a different scale than the width and height of the textboxes. Values for variables:height = 50
width = 50
numCols = 10
numRows = 10
vertCellOffset = 50

horzCellOffset = 50
private TextBox AddNewTextBox()
{
SOSTextBox txtBox = new SOSTextBox();
this.List.Add(txtBox);
hostForm.Controls.Add(txtBox);
txtBox.Height = height;
txtBox.Width = width;
float scrnWidth = hostForm.Width;
float scrnHeight = hostForm.Height;
txtBox.Top = (int)(((int)((Count – 1) / numCols) + 1) * vertCellOffset + (scrnHeight / 2 – ((numRows / 2 + 1) * vertCellOffset)));
txtBox.Left = (int)((((Count – 1) % numCols) + 1) * horzCellOffset + (scrnWidth / 2 – ((numCols / 2 + 1) * horzCellOffset)));
txtBox.ArrayLocation = new Point ((Count – 1) / numCols, (Count – 1) % numCols);
txtBox.Tag = Count;
txtBox.Font = new Font(txtBox.Font.FontFamily, height / 6.0f); // makes font size 1/3 of the height of textBox
txtBox.Text = "rn";
txtBox.KeyPress += new KeyPressEventHandler(KeyPressHandler);
return txtBox;
}


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *