richtextbox

WPF Richtextbox FontFace/FontSize

可紊 提交于 2019-12-22 12:13:32
问题 I am currently trying to create some basic word processor features in a WPF project. I am using a RichTextBox and am aware of all of the EditingCommands (ToggleBold, ToggleItalic...ect.). The thing I am stuck on is allowing the user to change the fontsize and font face like in MS Office where the value changes for only the selected text and if there is no selected text then the value will change for the current caret position. I have come up with a decent amount of code to get this to work,

WPF EditingCommands is not working when RichTextBox is just load/empty?

荒凉一梦 提交于 2019-12-22 11:08:13
问题 Here is a very simple code example: <DockPanel> <ToolBar DockPanel.Dock="Top" IsTabStop="False"> <ToggleButton MinWidth="40" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=XAMLRichBox}" TextBlock.FontWeight="Bold" IsTabStop="False">B</ToggleButton> </ToolBar> <RichTextBox x:Name="XAMLRichBox" SpellCheck.IsEnabled="True" MinHeight="100"/> </DockPanel> when I run it, after typing something into the RichTextBox , I can use the ToggleButton to get the BOLD effect, and

C#: Drag and Drop in WPF (Richtextbox)

时间秒杀一切 提交于 2019-12-22 10:45:09
问题 i want to implement a Drag/Drop mechanic in WPF, but it didn't work... With Windows-Forms it worked, ... First i set AllowDrop to True. In windows-forms you can already drag items into the richtextbox and the cursor changes. With WPF .... nothing happens. The nexT point: Implement DragEnter and DragDrop Methodes. I did it like the online-manuals says. (ok i had to try out something more, because DragDrop doesn't exists in WPF) I think all tutorials for drag/drop is only for Windowsforms,

How to get the current line in a RichTextBox control?

≡放荡痞女 提交于 2019-12-22 10:22:59
问题 Say I clicked somewhere inside a RichTextBox control. How can I get the current line the caret is currently on? Btw this is to retrieve the whole text string of that line. 回答1: That's what RichTextBox.GetLineFromCharIndex() does. Pass the SelectionStart property value. 回答2: This worked for me: this.WordWrap = false; int cursorPosition = this.SelectionStart; int lineIndex = this.GetLineFromCharIndex(cursorPosition); string lineText = this.Lines[lineIndex]; this.WordWrap = true; 回答3: One way is

How to remove annoying BEEP with RichTextBox

自古美人都是妖i 提交于 2019-12-22 09:40:17
问题 I placed a RichTextBox control on a new form and launched the project. So the RichTextBox.Text = ""; Each time I press Up or Down keys I heard the annoying BEEP sound! How to get rid of this issue? Using "e.SuppressKeyPress = true" in the KeyDown method locks the Cursor position. 回答1: Well, you can try suppressing the key only if the caret is on the first line and the key is up, or on the last line and the key is down or in position 0 and the key is left, etc. That said, this is how most

what is best way to sort lines in RichTextBox

核能气质少年 提交于 2019-12-22 07:09:21
问题 I'm looking for the best way to sort lines of RichTextBox, I'm using this at moment: public void SortLines(object sender, EventArgs e) { TextPointer pStart = TextInput.Document.ContentStart; TextPointer pEnd = TextInput.Document.ContentEnd; TextRange text = new TextRange(pStart, pEnd); string[] lines = text.Text.Split('\n'); Array.Sort(lines); text.Text = String.Join(String.Empty, lines); } Is there an best way to do this? When I call it, the cursor is placed into first RichTextBox line, how

richtextbox advanced editing

可紊 提交于 2019-12-22 05:33:18
问题 I am wanting to use advanced editing features with a RichTextBox i am using. For example, bold, italic, underline, font color.... I was wondering how i would get a toolbar that would show up at the top of the RichTextBox with those features? And i was wondering if there was anything that offered this functionality built in, or am i going to have to create all of it myself? I was thinking that the richtextbox would come with that toolbar by default, but it doesnt seem too. 回答1: I actually

Copy selected text from RichTextBox

戏子无情 提交于 2019-12-21 20:45:48
问题 I have searched around on the net but I cannot find a method of copying/cutting/pasting selected text from a RichTextBox . Even MSDN does not have an answer. The code they provide does not work: Copy() only appears to work on TextBoxes, not RichTextBoxes. 回答1: If you're using .NET 3.0 and above you can always use Clipboard.SetText() I found it useful to use the Clipboard when I want everything in the richTextBox without having to select everything first or when I need to change the string:

Convert XAML to FlowDocument to display in RichTextBox in WPF

南楼画角 提交于 2019-12-21 18:37:13
问题 I have some HTML, which i am converting to XAML using the library provided by Microsoft string t = HtmlToXamlConverter.ConvertHtmlToXaml(mail.HtmlDataString,true); now, from How to insert XAML into RichTextBox? i am using the following: private static FlowDocument SetRTF(string xamlString) { StringReader stringReader = new StringReader(xamlString); System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader); Section sec = XamlReader.Load(xmlReader) as Section; FlowDocument doc

Convert XAML to FlowDocument to display in RichTextBox in WPF

风格不统一 提交于 2019-12-21 18:36:59
问题 I have some HTML, which i am converting to XAML using the library provided by Microsoft string t = HtmlToXamlConverter.ConvertHtmlToXaml(mail.HtmlDataString,true); now, from How to insert XAML into RichTextBox? i am using the following: private static FlowDocument SetRTF(string xamlString) { StringReader stringReader = new StringReader(xamlString); System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader); Section sec = XamlReader.Load(xmlReader) as Section; FlowDocument doc