CS
java
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MyWpfTextEditor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void rtBox_Loaded(object sender, RoutedEventArgs e)
{
rtBox.AcceptsTab = true;
rtBox.AcceptsReturn = true;
rtBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
}
//Nastavení velikosti fontu
private void fontSizeComBox_Loaded(object sender, RoutedEventArgs e)
{
fontSizeComBox.ItemsSource = new List<double>() { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
}
private void fontSizeComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontSizeProperty, fontSizeComBox.SelectedValue.ToString());
rtBox.Focus();
}
//Nastavení typu fontu
private void fontNameComBox_Loaded(object sender, RoutedEventArgs e)
{
fontNameComBox.ItemsSource = Fonts.SystemFontFamilies.OrderBy(f => f.Source);
}
private void fontNameComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontFamilyProperty, fontNameComBox.SelectedItem);
rtBox.Focus();
}
//Nastavení RichTextBoxu
private void rtBox_TextChanged(object sender, TextChangedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontSizeProperty, fontSizeComBox.SelectedValue.ToString());
rtBox.Selection.ApplyPropertyValue(Inline.FontFamilyProperty, fontNameComBox.SelectedItem);
//Bold Button
if (boldToggButt.IsChecked.Value)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Bold);
}
else
{
rtBox.Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Normal);
}
//Italic Button
if (italicToggButt.IsChecked.Value)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Italic);
}
else
{
rtBox.Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Normal);
}
//Underline Button
if (underToggButt.IsChecked.Value)
{
rtBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
}
else
{
rtBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
}
}
//Nastavení Bold Button
private void boldToggButt_Checked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Bold);
}
private void boldToggButt_Unchecked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Normal);
}
//Nastavení Italic Button
private void italicToggButt_Checked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Italic);
}
private void italicToggButt_Unchecked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Normal);
}
//Nastavení Underline Button
private void underToggButt_Checked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
}
private void underToggButt_Unchecked(object sender, RoutedEventArgs e)
{
rtBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
}
}
}
Neformátovaný
Přidáno: 9.2.2015
Expirace: Neuvedeno