Click here to Skip to main content
15,844,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set font size of selected text in textbox?


Thanks!
Posted

You can't. The TextBox has a FontSize property, and that's what size the font is. If you want to change the size of selected text, I think you're going to have to fiddle around with a RichText control.
 
Share this answer
 
If you badly want to use a TextBox...let's say your religion bans you from using anything with the word Rich in it or maybe the RichTextBox has personally offended you in some way.

Then, you would have to overwrite the Paint event using subclassing and draw the text as you want it. Of course, this method would take a lot of work and is already done for you in the RichTextBox...but hey, maybe you just really don't like it.
 
Share this answer
 
Hi josip
this is a close answer that could lead you to your perfect solution
if i have time i will try to rewrite it and try to provide you exact answer (if i could) let me know

follow this program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace twoAFont
{
public partial class Form1 : Form
{
Font myFontBig, myFontSmall;
FontStyle styleBld, styleReg;
//Graphics gg = base.CreateGraphics();

public Form1()
{
InitializeComponent();
myFontBig = new Font("Andaluse", 16, styleBld);
myFontSmall = new Font("Andaluse", 10, styleReg);
}
private void button1_Click(object sender, EventArgs e)
{
//string s1, s2;
Graphics gg = textBox1.CreateGraphics();
TextRenderer.DrawText(gg, "Hellow Mr Josip", myFontBig,
new Point(100, 50), SystemColors.GradientActiveCaption);
TextRenderer.DrawText(gg, "Hellow OutLaw i am your friend khalid sabtan remember english is not my native languge so in certain case i have to ignore some words i will be carfull in future Bye", myFontSmall,
new Point(10, 50), SystemColors.GradientActiveCaption);
}
}
}
 
Share this answer
 
v3
Comments
William Winner 11-May-10 17:28pm    
That's great if you don't want to allow users to actually enter the text. Because the minute they change the text, your text disappears. There are just too many things to have to keep track of when doing this...as in, which font sizes to use for which selections, which character to start drawing at, etc...

A RichTextBox is much simpler and without an overrideable OnPaint, the only real way to do this would be through subclassing...

why re-think the wheel when the wheel works perfectly?
select property of the textbox from the list select font and size
khalid sabtan
 
Share this answer
 
Comments
#realJSOP 11-May-10 13:54pm    
That's not what he asked. He wants to change the size of JUST the text selected in the textbox. Unselected text will remain the size defined by the textbox.

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