I'm using a system.windows.controls.richtextbox, so the user can make notes. Now i want the the user to be able to change the font size with a combo box. The problem is, that i can't find a way to change the size of the selected text or, if there is no text selected, the size of the text from the cursor instead of everything.
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel
Foreground="#000000"
FontWeight="Bold"
VerticalAlignment="Center"
Text="{x:Static p:Resources.FontSize}"
/>
<ComboBox
x:Name="fontsize"
Margin="10,2,20,2"
>
</ComboBox>
</StackPanel>
<RichTextBox
Name="textbox"
Grid.Row="1" Grid.ColumnSpan="2" >
</RichTextBox>
</Grid>
public NotesSetup()
{
InitializeComponent();
this.AddFonts();
this.fonts.SelectedIndex = 1;
this.textbox.IsInactiveSelectionHighlightEnabled = true;
this.fonts.SelectionChanged += (s, a) =>
{
if (!this.textbox.Selection.IsEmpty)
{
}
else
{
this.textbox.FontFamily = this.fonts.SelectedItem as FontFamily;
}
};
for(int i = 8; i < 80; ++i)
{
this.fontsize.Items.Add(i);
}
this.fontsize.SelectedItem = 12;
this.fontsize.SelectionChanged += (s, a) =>
{
this.textbox.FontSize = int.Parse(this.fontsize.SelectedItem.ToString());
};
}
private void AddFonts()
{
foreach(System.Drawing.FontFamily f in System.Drawing.FontFamily.Families)
{
this.fonts.Items.Add(new FontFamily(f.GetName(0)));
}
}
}