c# - Form height and width measured differently than TextBox height -


i'm using function create textboxes class making arrays of textboxes, , want center grid form. after debugging, realized form height , width measured on different scale width , height of textboxes. values 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 height of textbox     txtbox.text = "\r\n";     txtbox.keypress += new keypresseventhandler(keypresshandler);     return txtbox; } 

i don't see question here, textboxes , form both "measured" in pixels. need concerned forms clientsize or clientrectangle (both in pixels).

if form not autosizing, in forms load event can call setclientsizecore(width, height), width , height size of "box" holds texstboxes.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -