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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
aun asghar3 reputationPosted Jul 5, 2007, 3:39 AM EDT
Felipe Marks72 reputationPosted Jul 5, 2007, 5:51 AM EDT
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.
AlanRank #669 · 3.6K reputationPosted Jul 5, 2007, 6:21 AM EDT
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 Marks72 reputationPosted Jul 6, 2007, 12:34 AM EDT
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
AlanRank #669 · 3.6K reputationPosted Jul 6, 2007, 2:41 AM EDT
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 Marks72 reputationPosted Jul 6, 2007, 4:03 AM EDT
whittler4 reputationPosted Jul 6, 2007, 4:49 AM EDT
AlanRank #669 · 3.6K reputationPosted Jul 6, 2007, 5:08 AM EDT
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;
Felipe Marks72 reputationPosted Jul 6, 2007, 5:23 AM EDT
thanks a million guys
God bless ya''ll!
Felipe Marks72 reputationPosted Jul 18, 2007, 1:09 AM EDT
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 Marks72 reputationPosted Jul 18, 2007, 1:11 AM EDT
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 Marks72 reputationPosted Jul 20, 2007, 5:50 AM EDT
richTextBox1.SelectionStart = (to equal the start of a string?)
AlanRank #669 · 3.6K reputationPosted Jul 20, 2007, 8:59 AM EDT
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 Marks72 reputationPosted Jul 22, 2007, 11:15 PM EDT