Hi there
I'd like to know how to format my output strings. Example,
if i want a specifc string to be underlinied on output
or make a border around strings and change the string size.
If you know if its possible please assist
thanks
Hi there
I'd like to know how to format my output strings. Example,
if i want a specifc string to be underlinied on output
or make a border around strings and change the string size.
If you know if its possible please assist
thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Felipe MarksPosted Jul 23, 2007, 3:15 AM
AlanPosted Jul 20, 2007, 12:59 PM
Try declaring an integer variable:
int nextStart = 0;
Now each time you're ready to add a new string to the RTB, store the length of the existing text in this variable before you add the new string:
nextStart = richTextBox1.TextLength;
You can then proceed as before, using this value (plus 1 for the space separating names) as the selection start:
name = "whatever";
richTextBox1.SelectionStart = nextStart + 1;
richTextBox1.Text += " " + name;
richTextBox1.SelectionLength = name.Length;
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Bold); // or whatever
richTextBox1.SelectionLength = 0;
Felipe MarksPosted Jul 20, 2007, 9:50 AM
richTextBox1.SelectionStart = (to equal the start of a string?)
Felipe MarksPosted Jul 18, 2007, 5:11 AM
One more thing please.....
This is working perfect n all, but Im working with so many strings and the positions of the
starting selection changes sometimes due to values and stuff.
Is there any way to make...
richTextBox1.SelectionStart = (to equal the end of the last string?)
thanks,
Eustace
Felipe MarksPosted Jul 18, 2007, 5:09 AM
One more thing please.....
This is working perfect n all, but Im working with so many strings and the positions of the
starting selection changes sometimes due to values and stuff.
Is there any way to make...
richTextBox1.SelectionStart = (
Felipe MarksPosted Jul 6, 2007, 9:23 AM
thanks a million guys
God bless ya''ll!
AlanPosted Jul 6, 2007, 9:08 AM
string
name = "Eustace"; string age = "20";richTextBox1.Text = name +
" " + age;richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = name.Length;
richTextBox1.SelectionFont =
new Font(richTextBox1.Font, FontStyle.Bold);richTextBox1.SelectionLength = 0;
whittlerPosted Jul 6, 2007, 8:49 AM
Felipe MarksPosted Jul 6, 2007, 8:03 AM
AlanPosted Jul 6, 2007, 6:41 AM
A normal TextBox can only handle one font/fontstyle at a time though a RichTextBox can handle several.
Sometimes you can simulate the effect of having mixed fonts by placing a number of labels adjacent to each other with different Font properties though this, of course, is only feasible if the strings have a fixed length.
Felipe MarksPosted Jul 6, 2007, 4:34 AM
Thanks so much for the help. It works perfectly fine but
is there a way to set the string property instead of the textbox?
cos im setting different string in a richtextbox but only want a few strings formatted
eg.
string name = "Eustace";
string age = "20";
textBox1.Text = name + " " + age;
How would i make the name bold or something and not the age?
thanks
AlanPosted Jul 5, 2007, 10:21 AM
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.font.aspx
If, for example, you wanted to display the same text in textBox2 as in textBox1, using the same font but in bold underline, then this code would do it:
textBox2.Font =
new Font(textBox1.Font, textBox1.Font.Style | FontStyle.Bold | FontStyle.Underline);textBox2.Text = textBox1.Text;
Felipe MarksPosted Jul 5, 2007, 9:51 AM
to make it more simple...
In html to underline this is the code... word
I'd like to do that in C#.net if the user enters a string variable
then i want to diplay it on another textarea but UNDERLINED
and increase size, bold ect.
I hope that explains it more.
aun asgharPosted Jul 5, 2007, 7:39 AM