Search code examples
c#winformstextboxtablelayoutpanel

Italic characters' bottom cut off in textBox


I have a TableLayoutPanel with TableLayoutPanels as rows. Each of the inner tableLayoutPanels has two rows. In the second row is a textBox showing an URL in italic style. However the url is cutoff in its height, characters like 'g' miss some pixels and '_' isn't shown at all.

So I tried to change the textBox' height - no change - tried to change the row size of the inner tableLayoutPanel - no change - tried to change the inner tableLayoutPanel's size itself - no change...

Ironically there's another label with italic text in the same row, it is bound to the row's bottom per anchor, but even if I use an anchor on the textBox it's still cutoff.

The relevant textBox code:

textBox2.Font = new System.Drawing.Font("Arial", 9.75F, 
    System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 
    ((byte)(0)));
textBox2.Location = new System.Drawing.Point(3, 21);
textBox2.Size = new System.Drawing.Size(454, 23);

The inner tlp code:

tableLayoutPanel2.RowStyles.Add(new 
    System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 
    80F));
tableLayoutPanel2.RowStyles.Add(new 
    System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 
    27F));
tableLayoutPanel2.Size = new System.Drawing.Size(607, 44);

Is it somehow possible to display italic underscores: (originally 8OG8vit_-Wg)

"8OG8vit_-Wg" cutoff

EDIT: Placed the textbox on it's outer groupbox and also the main form.

System.Windows.Forms.TextBox textBox2 = new System.Windows.Forms.TextBox();
textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
textBox2.Cursor = System.Windows.Forms.Cursors.IBeam;
textBox2.Font = new System.Drawing.Font("Arial", 9.75F, 
    System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 
    ((byte)(0)));
textBox2.Location = new System.Drawing.Point(100, 290);
textBox2.Name = "textBox2";
textBox2.ReadOnly = true;
textBox2.Size = new System.Drawing.Size(454, 15);
textBox2.Text = "8OG8vit_-Wg";
textBox2.BackColor = System.Drawing.Color.Coral;
groupBox1.Controls.Add(textBox2); // this.Controls.Add(textBox2); 

Here are the results:groupbox and mainform


Solution

  • I can't help but call this a bug.

    The combination of TextBox.Multiline = false and BorderStyle.None seems to make winforms overdo the client size reductions and will cut off descenders and underlines.

    The workaround is to give up on one of them; for the look you want simply make the TextBox.Multiline = true and all is as it should be..:

    enter image description here