8 Replies - 1111 Views - Last Post: 29 December 2012 - 11:11 AM Rate Topic: -----

#1 albut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-December 12

TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 06:22 AM

I am working on a C# application

I want to use custom Unicode fonts for writing in TextBox. My problem is that the font letters do not fit into the TextBox, they get cut off at the top and bottom.

The font is imported
this._fonts = new PrivateFontCollection();
this._fonts.AddFontFile("SyrCOMBatnan.otf");
customFontTextBox = new System.Drawing.Font(_fonts.Families[0], 25.0F);
this.textBox1.Font = customFontTextBox;



The TextBox is setup
this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F,     System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(326, 16);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.textBox1.ShortcutsEnabled = false;
this.textBox1.Size = new System.Drawing.Size(658, 179);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.TextBox1TextChanged);



This is how it looks like when i write.

Attached Image

Is there a way to change the size of the line size so that it will not cut of my letters?

Is This A Good Question/Topic? 0
  • +

Replies To: TextBox is cutting off my font on top and bottom

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 995
  • View blog
  • Posts: 2,386
  • Joined: 04-October 09

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 09:04 AM

Use the Font.GetHeight() method to determine the height of the font and adjust the size of the text box. Or change the size when you create the font.
Was This Post Helpful? 0
  • +
  • -

#3 albut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 10:02 AM

View PostMomerath, on 29 December 2012 - 09:04 AM, said:

Use the Font.GetHeight() method to determine the height of the font and adjust the size of the text box. Or change the size when you create the font.


Hi Momerath,
I have redone some parts of the code but it is not workig still. What is happening is that the line height seems to be the problem. It is cutting the text off:

1. I import the Font
2. Set the Font size
3. Set the Font for TextBox
4. Initiate the TextBox with Unicode text

Getting the Font Height has not helped me, I cannot change the Line Height.... Do you know of a way to do that?

this._fonts.AddFontFile("SyrCOMBatnan.otf");
this.customFont = new System.Drawing.Font(_fonts.Families[0], 20.0F);
double fontHeit = this.customFont.GetHeight();
String textBoxSyriac = "\u072C\u0736\u0720\u0736\u0720\u0736"; // \u072C\u0736\u0720\u0736\u0720\u0736
this.textBox1.Font = this.customFont;
this.textBox1.Text = textBoxSyriac;
this.textBox1.AutoSize = true;
String richTextBoxSyriac = "\u072C\u0736\u0720\u0736\u0720\u0736"; // \u072C\u0736\u0720\u0736\u0720\u0736
this.richTextBox1.Font = this.customFont;
this.richTextBox1.Text = richTextBoxSyriac;
this.richTextBox1.ZoomFactor = 2;


Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2884
  • View blog
  • Posts: 9,566
  • Joined: 12-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 10:19 AM

this.richTextBox1.ZoomFactor = 2;

Isn't this the issue? Perhaps move it earlier in the code.
Was This Post Helpful? 0
  • +
  • -

#5 albut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 10:30 AM

View Postandrewsw, on 29 December 2012 - 10:19 AM, said:

this.richTextBox1.ZoomFactor = 2;

Isn't this the issue? Perhaps move it earlier in the code.


Hi Andrewsw

I have tried with and without the ZoomFactor = 2...
What I have noticed is that it is cutting of more with ZoomFactor = 2. But even without the ZoomFactor it is cutting off a bit.

I really believe that there is an issue with the lineHeight.... If there is any way to change that for a TextBox or a RichTextBox i would appreciate some code example.

Regards
Alexander
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2884
  • View blog
  • Posts: 9,566
  • Joined: 12-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 10:34 AM

Perhaps

this.textBox1.AutoSize = true;

is not working well. Try false and leave the textbox at a specific height.
Was This Post Helpful? 0
  • +
  • -

#7 albut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 11:02 AM

View Postandrewsw, on 29 December 2012 - 10:34 AM, said:

Perhaps

this.textBox1.AutoSize = true;

is not working well. Try false and leave the textbox at a specific height.


I have tried that now:

this._fonts.AddFontFile("SyrCOMBatnan.otf");
this.customFont = new System.Drawing.Font(_fonts.Families[0], 25.0F);
double fontHeit = this.customFont.GetHeight();
String textBoxSyriac = "\u072C\u0736\u0720\u0736\u0720\u0736\u0737\u071B\u0713\u0737"; // \u072C\u0736\u0720\u0736\u0720\u0736
this.textBox1.Font = this.customFont;
this.textBox1.Text = textBoxSyriac;
this.textBox1.AutoSize = false;
String richTextBoxSyriac = "\u072C\u0736\u0720\u0736\u0720\u0736\u0737\u071B\u0713\u0737"; // \u072C\u0736\u0720\u0736\u0720\u0736
this.richTextBox1.Font = this.customFont;
this.richTextBox1.Text = richTextBoxSyriac;
//this.richTextBox1.ZoomFactor = -2;



And the TextBox is set here with position and Size.
// textBox1
this.textBox1.Location = new System.Drawing.Point(237, 12);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.textBox1.Size = new System.Drawing.Size(571, 72);
this.textBox1.TabIndex = 0;



You can still see that the text is getting chopped of still...
Attached Image

I am not sure what else I can try.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,572
  • Joined: 05-May 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 11:10 AM

Try using EM_SETRECT to change the formatting rectangle. You can read more about it on MSDN: http://msdn.microsof...formatting_rect

I doubt that will work for single line controls, but it'll probably suffice for your multiline control there.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2884
  • View blog
  • Posts: 9,566
  • Joined: 12-December 12

Re: TextBox is cutting off my font on top and bottom

Posted 29 December 2012 - 11:11 AM

My only other thought at this point would be to use .Refresh on the control, after all the changed-settings. Sorry if I'm not helping.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1