本文整理汇总了C#中System.Windows.Documents.TextRange.Save方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.Save方法的具体用法?C# TextRange.Save怎么用?C# TextRange.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertRtfToXaml
public static string ConvertRtfToXaml(string rtfText)
{
var richTextBox = new System.Windows.Controls.RichTextBox();
if (string.IsNullOrEmpty(rtfText))
return String.Empty;
var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
using (var rtfMemoryStream = new MemoryStream())
{
using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
{
rtfStreamWriter.Write(rtfText);
rtfStreamWriter.Flush();
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
textRange.Load(rtfMemoryStream, DataFormats.Rtf);
}
}
using (var rtfMemoryStream = new MemoryStream())
{
textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
textRange.Save(rtfMemoryStream, System.Windows.DataFormats.Xaml);
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
{
return rtfStreamReader.ReadToEnd();
}
}
}
示例2: UndoLevelStyle
public UndoLevelStyle(OutlinerNote note)
{
__NoteId = note.Id;
__Before = new MemoryStream[note.Columns.Count];
__After = new MemoryStream[note.Columns.Count];
__IsEmpty = true;
for (int i = 0; i < note.Columns.Count; i++)
{
FlowDocument document = note.Columns[i].ColumnData as FlowDocument;
if (document == null)
continue;
__Before[i] = new MemoryStream();
__After[i] = new MemoryStream();
TextRange range = new TextRange(document.ContentStart, document.ContentEnd);
range.Save(__Before[i], DataFormats.Xaml);
if (!range.IsEmpty)
__IsEmpty = false;
}
}
示例3: SaveData
public void SaveData()
{
TextRange sourceDocument = new TextRange(mainRTB.Document.ContentStart, mainRTB.Document.ContentEnd);
string rtf = "";
using (MemoryStream stream = new MemoryStream())
{
sourceDocument.Save(stream, DataFormats.Rtf);
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
rtf = reader.ReadToEnd();
}
}
if (mIsSummaryNarrative)
{
mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrative"] = sourceDocument.Text;
mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrativeFormat"] = rtf;
}
else
{
mDataSet.Tables["i9Narrative"].Rows[0]["Narrative"] = sourceDocument.Text;
mDataSet.Tables["i9Narrative"].Rows[0]["NarrativeFormat"] = rtf;
}
}
示例4: AddBlock
public static void AddBlock(Block from, FlowDocument to)
{
if (from != null)
{
//if (from is ItemsContent)
//{
// ((ItemsContent)from).RunBeforeCopy();
//}
//else
{
TextRange range = new TextRange(from.ContentStart, from.ContentEnd);
MemoryStream stream = new MemoryStream();
System.Windows.Markup.XamlWriter.Save(range, stream);
range.Save(stream, DataFormats.XamlPackage);
TextRange textRange2 = new TextRange(to.ContentEnd, to.ContentEnd);
textRange2.Load(stream, DataFormats.XamlPackage);
}
}
}
示例5: open_button_Click
private void open_button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialog1.Filter = @"Evennote File(*.note)|*.note";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == true)
{
Note temp = Evennote.OpenNoteFromFile(openFileDialog1.FileName);
titleTextBox.Text = temp.Title;
using (MemoryStream mem = new MemoryStream())
{
TextRange range = new TextRange(temp.Text.ContentStart,
temp.Text.ContentEnd);
range.Save(mem, DataFormats.XamlPackage);
mem.Position = 0;
TextRange kange = new TextRange(richTextBox.Document.ContentStart,
richTextBox.Document.ContentEnd);
kange.Load(mem, DataFormats.XamlPackage);
}
}
}
示例6: GetPaginator
/// <summary>
/// 获取文档分页器
/// </summary>
/// <param name="pageWidth"></param>
/// <param name="pageHeight"></param>
/// <returns></returns>
public DocumentPaginator GetPaginator(double pageWidth,double pageHeight)
{
//将RichTextBox的文档内容转为XAML
TextRange originalRange = new TextRange(
_textBox.Document.ContentStart,
_textBox.Document.ContentEnd
);
MemoryStream memoryStream = new MemoryStream();
originalRange.Save(memoryStream, System.Windows.DataFormats.XamlPackage);
//根据XAML将流文档复制一份
FlowDocument copy = new FlowDocument();
TextRange copyRange = new TextRange(
copy.ContentStart,
copy.ContentEnd
);
copyRange.Load(memoryStream, System.Windows.DataFormats.XamlPackage);
DocumentPaginator paginator =
((IDocumentPaginatorSource)copy).DocumentPaginator;
//转换为新的分页器
return new PrintingPaginator(
paginator,new Size( pageWidth,pageHeight),
new Size(DPI,DPI)
);
}
示例7: LoadRange
private static void LoadRange(RichTextBox richTextBox, TextRange range)
{
MemoryStream buffer = new MemoryStream();
range.Save(buffer, DataFormats.Rtf);
var rtf = Encoding.UTF8.GetString(buffer.ToArray());
SetContent(richTextBox, rtf);
}
示例8: SavePost
public void SavePost(string postFile)
{
FileStream fileStream = new FileStream(postFile, FileMode.Create);
TextRange range = new TextRange(_postEdit.Document.ContentStart, _postEdit.Document.ContentEnd);
range.Save(fileStream, DataFormats.Rtf);
fileStream.Close();
}
示例9: ConvertRtfToXaml
private static string ConvertRtfToXaml(string rtfText)
{
var richTextBox = new RichTextBox();
if (string.IsNullOrEmpty(rtfText)) return "";
var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
//Create a MemoryStream of the Rtf content
using (var rtfMemoryStream = new MemoryStream())
{
using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
{
rtfStreamWriter.Write(rtfText);
rtfStreamWriter.Flush();
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
//Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
textRange.Load(rtfMemoryStream, DataFormats.Rtf);
}
}
using (var rtfMemoryStream = new MemoryStream())
{
textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
textRange.Save(rtfMemoryStream, DataFormats.Xaml);
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
{
return rtfStreamReader.ReadToEnd();
}
}
}
示例10: GetText
protected override string GetText()
{
var rnge = new TextRange(_doc.ContentStart, _doc.ContentEnd);
var stream = new MemoryStream();
rnge.Save(stream, DataFormats.Rtf);
return UTF8Encoding.UTF8.GetString(stream.ToArray());
}
示例11: GetText
public string GetText(FlowDocument document)
{
var tr = new TextRange(document.ContentStart, document.ContentEnd);
using (var ms = new MemoryStream())
{
tr.Save(ms, DataFormats.Xaml);
return Encoding.Default.GetString(ms.ToArray());
}
}
示例12: GetText
/// <summary>
/// Gets the RTF Content of a flow document as UTF-8 Encoded string.
/// </summary>
/// <param name="document">The flow document for the RTF extracting.</param>
/// <returns>The RTF content of the flow document as UTF-8 Encoded string.</returns>
public string GetText(FlowDocument document)
{
TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
tr.Save(ms, DataFormats.Rtf);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
示例13: GetText
public string GetText(System.Windows.Documents.FlowDocument document)
{
TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
tr.Save(ms, DataFormats.Xaml);
return ASCIIEncoding.Default.GetString(ms.ToArray());
}
}
示例14: SaveCore
protected override void SaveCore(IDocument document, string fileName)
{
FlowDocument flowDocument = ((RichTextDocument)document).Content;
TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
using (FileStream stream = new FileStream(fileName, FileMode.Create))
{
range.Save(stream, DataFormats.Rtf);
}
}
示例15: Render
public override void Render (IConsoleBufferSource buffer)
{
var document = new FlowDocument();
RenderToFlowDocument(buffer, document);
var content = new TextRange(document.ContentStart, document.ContentEnd);
content.Save(_output, DataFormats.Rtf);
if (_leaveOpen)
_output.Flush();
else
_output.Dispose();
}