Click here to Skip to main content
15,885,979 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have form in which there are n number of text boxses wihch of height 9 px and i want to allow text which is of font size 8.5 px but text box not allowing the same.
Posted
Comments
Sandeep Mewara 26-Feb-13 11:49am    
Why set textbox height? It should be picked automatically based on font.

1 solution

Hi,
In WinForm if you have font "Microsoft Sans Serif, 8.25pt" the minimum height you can have for the textbox is 20px. If you get the Font size to 1.5, the you might get the text box height to 10px. This is extremely unreadable.

So, if you set your text box height to 9px then you will get 1px Font Size. if you set the textbox font size to 8.5px then your textbox height will automatically adjust to 20px.

anyhow the code to set the font size is
C#
textBox1.Font = new Font("Microsoft Sans Serif", 8.5f);


I hope this helps you.

Regards
Jegan
 
Share this answer
 
Comments
vishal_h 26-Feb-13 12:33pm    
I want to set font size to 15 px on text box of height 18 px...I set padding to zero but it does not work..
Jegan Thiyagesan 27-Feb-13 5:05am    
You are again missing the point, Font size and the Text box height are related, if you set the font size to 15px then your textbox height will increase to 30px. you cannot increase one and decrease another, they both will increase or decrease relatively.
vishal_h 27-Feb-13 6:25am    
Then if i have n number of text boxes and i want to fix it into small area then if i decrease the height of textbox it will also effect my font size whether i dont want margin from text to textbox border..
Jegan Thiyagesan 27-Feb-13 6:38am    
You cannot change the margin of the fonts, But you can change the Font family to fit in your text box, such as Lucida Console font family with 8px will adjust the height of the text box to 15px, and just about readable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900