안녕하세요, WPF에서 RichTextBox
을 사용하는 편집기를 개발 중입니다. 사용자가 선택할 수있는 글꼴을 구현할 수있는 기능을 구현해야합니다. Text
일부 텍스트를 선택한 경우 아무 것도 선택하지 않으면 글꼴을 설정해야합니다. 새로운 텍스트. 나는 후자의 경우에 (FontStyle
같은 FontSize
) RTB의 글꼴 속성을 설정하면 내가 사용자가 텍스트를 입력하면 새로운 텍스트 (예 :이 새 글꼴 설정으로 올 것이다 글꼴 속성을 설정 어떻게, 전체 텍스트의 속성을 설정합니다). 나는 내가 무엇을 발견 등의 글꼴 크기, 가족, 색상을 변경할 수있는 도구 모음을 구현했습니다RichTextBox에서 글꼴 속성 설정
0
A
답변
5
는 세부 사항은 WPF의를 RichTextBox에 까다로운 일이 될 수있다. 선택 글꼴을 설정하는 것은 의미가 있습니다. 그러나 텍스트 상자의 기본 글꼴 속성과 현재 대립 할 캐럿 속성도 있습니다. 다음은 글꼴 크기로 대부분의 경우 작동하도록 작성한 것입니다. fontfamily 및 fontcolor에 대한 프로세스가 동일해야합니다. 희망이 도움이됩니다.
public static void SetFontSize(RichTextBox target, double value)
{
// Make sure we have a richtextbox.
if (target == null)
return;
// Make sure we have a selection. Should have one even if there is no text selected.
if (target.Selection != null)
{
// Check whether there is text selected or just sitting at cursor
if (target.Selection.IsEmpty)
{
// Check to see if we are at the start of the textbox and nothing has been added yet
if (target.Selection.Start.Paragraph == null)
{
// Add a new paragraph object to the richtextbox with the fontsize
Paragraph p = new Paragraph();
p.FontSize = value;
target.Document.Blocks.Add(p);
}
else
{
// Get current position of cursor
TextPointer curCaret = target.CaretPosition;
// Get the current block object that the cursor is in
Block curBlock = target.Document.Blocks.Where
(x => x.ContentStart.CompareTo(curCaret) == -1 && x.ContentEnd.CompareTo(curCaret) == 1).FirstOrDefault();
if (curBlock != null)
{
Paragraph curParagraph = curBlock as Paragraph;
// Create a new run object with the fontsize, and add it to the current block
Run newRun = new Run();
newRun.FontSize = value;
curParagraph.Inlines.Add(newRun);
// Reset the cursor into the new block.
// If we don't do this, the font size will default again when you start typing.
target.CaretPosition = newRun.ElementStart;
}
}
}
else // There is selected text, so change the fontsize of the selection
{
TextRange selectionTextRange = new TextRange(target.Selection.Start, target.Selection.End);
selectionTextRange.ApplyPropertyValue(TextElement.FontSizeProperty, value);
}
}
// Reset the focus onto the richtextbox after selecting the font in a toolbar etc
target.Focus();
}
관련 문제
- 1. RichTextBox에서 글꼴 스타일의 char 인덱스 찾기
- 2. 작은 대문자 글꼴 속성?
- 3. wpf converter : 다중 속성 설정
- 4. Firemonkey에서 글꼴 설정
- 5. CLinkCtrl의 글꼴 크기 설정
- 6. JTextArea에서 글꼴 설정
- 7. 새우의 글꼴 색 설정
- 8. Windows에서 emacs 글꼴 설정
- 9. CSS 글꼴 속성 대 텍스트 속성
- 10. UIButton 하위 클래스 - 속성 설정?
- 11. 차트 시리즈의 글꼴 설정 툴팁
- 12. iPhone 글꼴 : 작은 모자 설정
- 13. DropDownListFor에 대한 글꼴 크기 설정
- 14. 영어 이외의 언어 글꼴 설정
- 15. C#의 기본 글꼴 설정
- 16. 변수를 사용하여 CGBitmapContext.SelectFont에 글꼴 설정
- 17. SWT 셸의 기본 글꼴 설정
- 18. Java/Swing에서 시스템 글꼴 속성 가져 오기
- 19. 글꼴 뷰어 작성 - 글꼴 속성 가져 오기, 동적으로 ttf로드
- 20. QTMovie 속성 설정
- 21. asp.net의 프로필 속성 설정
- 22. Webby 레이아웃의 속성 설정
- 23. 하위보기의 속성 설정
- 24. GLSL - 설정 속성 확인
- 25. 설정 자바 시스템 속성
- 26. WPF의보기에서 ViewModel의 속성 설정
- 27. 신속하게 클래스 속성 설정
- 28. NameValueCollection에서 클래스 속성 설정
- 29. minlength 속성 설정 jQuery
- 30. SVN : 디렉토리에만 속성 설정
아름다운 대답 –