Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I think this is a basic question but still i am posting because i failed how to search my query in google instead i thought i can frame my question. I am new to .net.
So i am working on some task where i got few lines of code as shown below. I need the text in "" should be bold and the result will be anyway normal.

Code 1:

AB+= " SHORT TEXT " + ac.value;
AB+= " LONG TEXT " + ac.value;

Code 2:

string builder sb = new stringbuilder();
sb.appendline("NAME:\t" + name.value);
sb.appendline("PLACE:\t" + place.value);

In the secnod case, i am working from middle of the project so i am not sure what to use to make the text (NAME and PLACE) bold.

Any help would be appreciated.

What I have tried:

Tried googling but the framing of my question is bad.
Posted
Updated 22-Sep-16 5:27am
Comments
[no name] 22-Sep-16 8:47am    
Not sure why you could not find it, https://msdn.microsoft.com/en-us/library/system.drawing.font.bold(v=vs.110).aspx
Member 8010354 22-Sep-16 9:02am    
but in code 2, he used \t for space and ther for bold, what i have to use?
[no name] 22-Sep-16 9:24am    
That makes no sense. You would do exactly the same thing when you display the string. You don't make a string bold, you display it bold using a font.
F-ES Sitecore 22-Sep-16 11:42am    
As said already, you need to say where this text is appearing as that will dictate the solution.

A string doesn't have any formatting associated with it - it can't be "bold" or "underlined" or even "Times New Roman" - it's is literally just a sequence of characters.
Formatting is only applied when it is presented to an output device, be that a browser, a form, or a printer - and then the method to apply that formatting will vary from output device to output device. For a webpage, to boldify text would mean adding bold tags round it:
HTML
this is normal <b>this is bold</b> this is normal again

For printing, you would need to use Graphics.DrawString three times, with a Bold font in the middle, and that's complicated because you need to measure the strings to make sure you are locating them in the right place on the page when you print them - bold characters are wider than non bold for the same font and size.
For a WinForms app, it's even worse: you can't apply formatting to any part of a string in a TextBox or Label control, but can in a RichTextBox provided you include RTF code in your string.

So no, it's not a "basic" question - and it's very, very far from a trivial solution depending on the environment you are working in.
 
Share this answer
 
Comments
F-ES Sitecore 22-Sep-16 11:41am    
And of course if this output is to a console app then that's a different solution too.
As OriginalGriff mentioned, a solution depends on what you're trying to achieve.

Let say, you store some data in xml file and you'd like to display that data for end-user. You can use xsl transformation, which enables you to create html document from xml[^]. Please, check this:
Hello, World! (XSLT)[^]
How to apply an XSL transformation to an XML document by using Visual C# [^]
 
Share this answer
 

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