Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new TextRange(Document.ContentStart, Document.ContentEnd).IsEmpty
- var start = rtb.Document.ContentStart;
- var end = rtb.Document.ContentEnd;
- int difference = start.GetOffsetToPosition(end);
- public bool IsRichTextBoxEmpty(RichTextBox rtb)
- {
- if (rtb.Document.Blocks.Count == 0) return true;
- TextPointer startPointer = rtb.Document.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
- TextPointer endPointer = rtb.Document.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);
- return startPointer.CompareTo(endPointer) == 0;
- }
- bool IsEmpty(Document document)
- {
- string text = new TextRange(Document.ContentStart, Document.ContentEnd).Text;
- if (string.IsNullOrWhiteSpace(text) == false)
- return false;
- else
- {
- if (document.Blocks.OfType<BlockUIContainer>()
- .Select(c => c.Child).OfType<Image>()
- .Any())
- return false;
- }
- return true;
- }
- string text = new TextRange(Document.ContentStart, Document.ContentEnd).Text;
- return !String.IsNullOrWhiteSpace(text);
- Private Function RichTextBoxIsEmpty(BYVAL rtb As RichTextBox) As Boolean
- Dim ReturnCode As Boolean = True
- Dim text As String = New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd).Text
- If String.IsNullOrWhiteSpace(text) Then
- For Each block As Block In rtb.Document.Blocks
- 'check for an image
- If TypeOf block Is Paragraph Then
- Dim paragraph As Paragraph = DirectCast(block, Paragraph)
- For Each inline As Inline In paragraph.Inlines
- If TypeOf inline Is InlineUIContainer Then
- Dim uiContainer As InlineUIContainer = DirectCast(inline, InlineUIContainer)
- If TypeOf uiContainer.Child Is Image Then
- ReturnCode = False
- Exit For
- End If
- End If
- Next
- End If
- ' Check for a table
- If TypeOf block Is Table Then
- ReturnCode = False
- Exit For
- End If
- Next
- Else
- ReturnCode = False
- End If
- Return ReturnCode
- End Function
- var rtf = GetRtfText();
- var start = Document.ContentStart;
- var end = Document.ContentEnd;
- var difference = start.GetOffsetToPosition(end);
- HasText = difference > 4 || rtf.Length > 350;
- public string GetRtfText()
- {
- var tr = new TextRange(Document.ContentStart, Document.ContentEnd);
- using (var ms = new MemoryStream())
- {
- tr.Save(ms, DataFormats.Rtf);
- return Encoding.Default.GetString(ms.ToArray());
- }
- }
Add Comment
Please, Sign In to add comment