Click here to Skip to main content
15,071,729 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making the project as coding in c# and designing in silverlight3..

I have three toggle button "bold" , "Italics" , "underline"


I have done the coding for bold and italics


void _btnBold1_Click(object sender, RoutedEventArgs e)
{
try
{
if (_btnBold1.IsChecked.HasValue)
{
txtMailBody1.Selection.FontWeight = _btnBold1.IsChecked.Value ? FontWeights.Bold : FontWeights.Normal;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}


void _btnItalics1_Click(object sender, RoutedEventArgs e)
{
try
{
if (_btnItalics1.IsChecked.HasValue)
{
txtMailBody1.Selection.FontStyle = _btnItalics1.IsChecked.Value ? FontStyles.Italic : FontStyles.Normal;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}







but In don't know what coding is required for underline....



void _btnUnderline_Click(object sender, RoutedEventArgs e)
{
if (_btnUnderline.IsChecked.HasValue)
{

}
}
Posted
Updated 23-Jan-10 19:09pm
v4

Try using something like -
txtMailBody1.TextDecorations=TextDecorations.Underline;
   
v2
If this is the Component one rich text box - have a look at their documentation here.

They provide the following solution.
You need to do the same

private void _btnUnderline_Click(object sender, RoutedEventArgs e)
{
bool underline = _rtb.Selection.TextDecorations ==
TextDecorations.Underline;
_rtb.Selection.TextDecorations = underline
? null
: TextDecorations.Underline;
}


Your code will be something like this - txtMailBody1.Selection.TextDecorations == TextDecoration.Underline;
   
v2

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