Need to make string bold

Posted by Ganeshd under C# on 1/25/2012 | Points: 10 | Views : 5224 | Status : [Member] | Replies : 2
i am working in MVVM, i am binding a string to the rich textbox, in that some portion of string i need to make bold.




Responses

Posted by: Hemanthlaxmi on: 1/25/2012 [Member] Starter | Points: 25

Up
0
Down
You can do that using this method
/// <summary>

/// This method highlights the assigned text with the specified color.
/// </summary>
/// <param name="textToMark">The text to be marked.</param>
/// <param name="color">The new Backgroundcolor.</param>
/// <param name="richTextBox">The RichTextBox.</param>
/// <param name="startIndex">The zero-based starting caracter position.</param>
public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox, int startIndex)
{
if (startIndex < 0 || startIndex > textToMark.Length-1) startIndex = 0;

System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false);
try
{
foreach (string line in richTextBox.Lines)
{
if (line.Contains(textToMark))
{
richTextBox.Select(startIndex, line.Length);
richTextBox.SelectionBackColor = color;
}
startIndex += line.Length +1;
}
}
catch
{ }
}


If this helps you .
Please "Mark as Answer"

Ganeshd, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshd on: 1/25/2012 [Member] Starter | Points: 25

Up
0
Down
if (NotesList != null && NotesList.Count > 0)
{
_summaryNote = "";
foreach (NoteDO note in NotesList)
{
_summaryNote += note.Date.ToString() + " " + note.UserName + "\n" + note.Notes + "\n";
}
}
NotifyOfPropertyChange(() => SummaryNotes);



"note.Date.ToString() + " " + note.UserName" this part i need to make bold how can i make

Ganeshd, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response