richtextbox

Underscore acts as a separator C# RTF Box

狂风中的少年 提交于 2019-12-01 14:34:32
I am working on a Winforms application and using Find on the RichTextBox control to find particular keywords to style. For some reason, despite specifying the WholeWord flag, the Find seems to treat a word with an underscore in it as 2 separate words (and styles the matching half). The function call is: richTextBox1.Find("Keyword", RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord); Why is this happening? Can I override it/fix it somehow? Eric Brown You can, although it's a bit hairy. You need to specify a custom word breaking procedure for your rich text box, and you want to override

Windows Forms RichTextBox cursor position

懵懂的女人 提交于 2019-12-01 14:25:56
问题 I have a C# Windows Forms program that has a RichTextBox control. Whenever the text inside the box is changed (other than typing that change), the cursor goes back to the beginning. In other words, when the text in the RichTextBox is changed by using the Text property, it makes the cursor jump back. How can I keep the cursor in the same position or move it along with the edited text? Thanks 回答1: You can store the cursor position before making the change, and then restore it afterwards: int i

Preventing a RichTextBox operation from being added to the control's Undo stack

こ雲淡風輕ζ 提交于 2019-12-01 13:58:52
Editing a RichTextBox control's text (more specifically, modifying selection font/color) programmatically seems to be tracked in the control's built in undo stack. Is there a way, short of writing my own undo/redo "manager", to prevent certain actions/operations from being added to the undo stack ? No cando. At best you can flush the undo stack completely by sending EM_SETUNDOLIMIT twice. EM_SETTEXTEX offers the same option with the ST_DEFAULT flag. Surely not what you want. Look at ScintillaNET for a real editor. If you came here when searching for a WPF c# answer you have a good one here

How to Display ObservableCollection<string> in a UserControl

与世无争的帅哥 提交于 2019-12-01 13:29:34
I'm new to WPF and I've found some similar questions but can't quite figure out the last part. I have a ViewModel with an ObservableCollection that contains error messages. I want to display these on the form AND allow the user to select and copy all or part of the messages. (In the past in WinForm apps I used a RichTextBox for this, but I can't figure out how to bind to one to the collection in WPF.) I got the look I was after with the following xaml, but there is no built-in way to select and copy like I could with a RichTextBox. Does anyone know which control I should use or if there is way

How to know if RichTextBox vertical Scrollbar reached the max value?

血红的双手。 提交于 2019-12-01 13:18:36
When using the richtextbox method "ScrollToCaret" I need to know if the scrollbar reached the top/bottom margin. This is because when vertical scrollbar is full scrolled to bottom then if I use again the "ScrollToCaret" method then it produces a weird visual effect in the control 'cause it try and retry to scroll down but theres nothing more to scroll, I can't understand this weird logic of richtextbox control. I hope you could understand me, forgive my English. PS: I'm using the default richtextbox vertical scrollbar. You have to deal with a little Win32 . The win32 method GetScrollInfo is

Underscore acts as a separator C# RTF Box

我是研究僧i 提交于 2019-12-01 12:36:08
问题 I am working on a Winforms application and using Find on the RichTextBox control to find particular keywords to style. For some reason, despite specifying the WholeWord flag, the Find seems to treat a word with an underscore in it as 2 separate words (and styles the matching half). The function call is: richTextBox1.Find("Keyword", RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord); Why is this happening? Can I override it/fix it somehow? 回答1: You can, although it's a bit hairy. You

Extracting images from RichTextBox

折月煮酒 提交于 2019-12-01 11:31:49
I have an application where users may insert images into a RichTextBox. I'd like to be able to replace all the images in the RTF with some token and store the images in separate files. I'll inject the images back into the RTF later. I've managed to get the insertion working but ended up resorting to pasting them via the Clipboard (very like Insert an image into RTF document in C# ). The trouble now is how to extract the images. How do I programatically select an image in a RichTextBox? Do I have to go back through the clipboard? Something like: IDataObject data = Clipboard.GetDataObject();

C1RichTextBox with custom copy/paste behavior

自闭症网瘾萝莉.ら 提交于 2019-12-01 10:31:57
When using C1RichTextBox in Silverlight 5 with IE 10, I am facing two major issues: During a clipboard paste operation, how can I detect if the content was copied from another C1RichTextBox in my Silverlight application or from an external application? From external applications, only text should be pasted without formatting. Copy/Pasting large inline images from one C1RichTextBox to another does not work. The <img> elements have the image content stored in their data URL. If the image becomes too large (approx 1MB), the src attribute is dropped when copied to the clipboard. The solution

Extracting images from RichTextBox

淺唱寂寞╮ 提交于 2019-12-01 09:16:43
问题 I have an application where users may insert images into a RichTextBox. I'd like to be able to replace all the images in the RTF with some token and store the images in separate files. I'll inject the images back into the RTF later. I've managed to get the insertion working but ended up resorting to pasting them via the Clipboard (very like Insert an image into RTF document in C#). The trouble now is how to extract the images. How do I programatically select an image in a RichTextBox? Do I

Winforms RichTextBox: How can I scroll the caret to the middle of the RichTextBox?

孤街浪徒 提交于 2019-12-01 08:52:53
I want to scroll a RichTextBox so that the caret is approximately in the middle of the RichTextBox. Something like RichTextBox.ScrollToCaret() , except I don't want to put the caret at the very top. I saw Winforms: Screen Location of Caret Position , and of course also saw the Win32 function SetCaretPos() . But I'm not sure how to translate the x,y required by SetCaretPos into lines in the richtextbox. If the rich text box is in _rtb, then you can get the number of visible lines: public int NumberOfVisibleLines { get { int topIndex = _rtb.GetCharIndexFromPosition(new System.Drawing.Point(1, 1)