关于TXTextControl的使用,请参看:
TXTextControl详解
啥都不说,先上效果图:
XAML:
啥都不说,先上效果图:
XAML:
<Page x:Class="TX_Text_Control_Demo.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1" xmlns:my="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_Load" Click="MenuItem_Click"></MenuItem>
<MenuItem Header="_Save" Click="MenuItem_Click_1"></MenuItem>
</MenuItem>
<MenuItem Header="_FormFields" Name="FormFieldMenu" SubmenuOpened="FormFields_Insert_SubmenuOpened">
<MenuItem Header="_Insert" Name="FormFields_Insert" Click="FormFields_Insert_Click"></MenuItem>
<MenuItem Header="_Properties" Name="FormFields_Properties" Click="FormFields_Properties_Click"></MenuItem>
</MenuItem>
</Menu>
<my:ButtonBar Name="buttonBar1" />
<my:RulerBar Name="rulerBar1" />
<my:StatusBar Name="statusBar1" />
<my:RulerBar Name="rulerBar2" VerticalAlignment="Stretch" HorizontalAlignment="Left" DockPanel.Dock="Left"/>
<my:TextControl Name="textControl1" ButtonBar="buttonBar1" RulerBar="rulerBar1" StatusBar="statusBar1" VerticalRulerBar="rulerBar2"
HideSelection="False" Loaded="textControl1_Loaded"/>
</DockPanel>
</Page>
后台代码:
后台代码:
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings();
ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord;
ls.ApplicationFieldTypeNames = new string[] { "FORMTEXT" };
textControl1.Load(TXTextControl.StreamType.MSWord | TXTextControl.StreamType.WordprocessingML, ls);
}
private void MenuItem_Click_1(object sender, RoutedEventArgs e)
{
textControl1.Save(TXTextControl.StreamType.MSWord | TXTextControl.StreamType.WordprocessingML);
}
private void FormFields_Insert_SubmenuOpened(object sender, RoutedEventArgs e)
{
if (textControl1.ApplicationFields.GetItem() == null)
FormFields_Properties.IsEnabled = false;
else
FormFields_Properties.IsEnabled = true;
}
private void FormFields_Properties_Click(object sender, RoutedEventArgs e)
{
if (textControl1.ApplicationFields.GetItem().TypeName == "FORMTEXT")
{
FormText curFormText = new FormText(textControl1.ApplicationFields.GetItem());
curFormText.ShowDialog();
}
}
private void FormFields_Insert_Click(object sender, RoutedEventArgs e)
{
FormText ftField = new FormText();
ftField.Text = "[New FormTextboxField]";
textControl1.ApplicationFields.Add(ftField.ApplicationField);
}
private void textControl1_Loaded(object sender, RoutedEventArgs e)
{
textControl1.Focus();
}