richtextbox

RichTextBox Binding is broken when text is manually modified or cleared

北慕城南 提交于 2020-04-07 08:09:30
问题 I have a RichTextBox bound to a string. Using C# I generate a string that writes to it. But if I want to manually change the text by clicking into the RichTextBox and deleting it with the backspace key, or pressing Enter to make a new line, the binding becomes broken and I can no longer programmatically write to it with the string a second time. XAML <RichTextBox x:Name="rtbScriptView" Margin="11,71,280,56" Padding="10,10,10,48" FontSize="14" Grid.ColumnSpan="1" VerticalScrollBarVisibility=

RichTextBox with text filtering

好久不见. 提交于 2020-03-06 04:52:06
问题 How can I implement in richTextBox something like filter (connected e.g. with combobox ) that'll be responsible for showing only lines containing selected word (filters)? I'm not talking about removing other lines - only "hide". Is it possible? Eventually I could use another type control, but if it's not neccessary I'd like to use richTextBox. I thought now, about storing data in some structure, and make filtering based on this used structure. But don't know if it's efficient solution. 回答1:

Get max line width in a RichTextBox

十年热恋 提交于 2020-03-04 23:09:31
问题 I'm trying to calculate the max horizontal scroll position of a RichTextBox, I'm aware that I could do something like: Graphics g = richTextBox1.CreateGraphics(); float maxLineWidth = 0; foreach(string line in richTextBox1.Lines) { float thisLineWidth = g.MeasureString(line, richTextBox1.Font).Width; if(thisLineWidth > maxLineWidth) { maxLineWidth = thisLineWidth; } } But is there a more efficient way? There's a win api function GetScrollRange which is used like: int min = 0; int max = 0;

Why can't I change the color of repeated words in a RichTextBox?

二次信任 提交于 2020-02-03 09:57:31
问题 My program has to find specific words inside a RichTextBox and change their color (simple syntax highlighter). I am using Regex to find the words. I'm able to find them all but if my text contains 2 or more of the same word, I can only change the color of the first one, the other ones get untouched. Dim words As String = "(in|handles|object|sub|private|dim|as|then|if|regex)" Dim rex As New Regex(words) Dim mc As MatchCollection = rex.Matches(RichTextBox1.Text.ToLower) Dim lower_case_text As

How to insert XAML into RichTextBox?

房东的猫 提交于 2020-02-02 04:54:27
问题 A XAML text stored in database, how can I show its text in a RichTextBox after reading the XAML by XmlReader? StringReader stringReader = new StringReader(xamlString); XmlReader xmlReader = XmlReader.Create(stringReader); rt.Document = ??? ------UPDATE------------------- here is the xamlString contents: <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us"

How to insert XAML into RichTextBox?

佐手、 提交于 2020-02-02 04:53:49
问题 A XAML text stored in database, how can I show its text in a RichTextBox after reading the XAML by XmlReader? StringReader stringReader = new StringReader(xamlString); XmlReader xmlReader = XmlReader.Create(stringReader); rt.Document = ??? ------UPDATE------------------- here is the xamlString contents: <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us"

Readonly richtextbox changing color of keyword C#

好久不见. 提交于 2020-01-25 00:58:09
问题 I have a rich text box that i am using to display an example of the Hello World program and want the keywords such as 'using' 'namespace' 'class' 'static' 'void' 'string' to display blue. I have got 'using' to display blue but only when the user starts to type or types 'using' I want the richtextbox to be read only not allowing an user input into it Here is my code: private void rtb_TextChanged(object sender, EventArgs e) { string find = "using"; if (rtb.Text.Contains(find)) { var matchString

WPF RichTextBox seamless TextBoxes as InlineUIContainers

一曲冷凌霜 提交于 2020-01-25 00:21:06
问题 I'm attempting to "Tokenize" text inside of a WPF RichTextBox control. Whenever the user types a ";", the text before it is placed into a new TextBox contained within an InlineUiContainer. This allows the text to be programmatically different, and yet still be editable. I was able to remove the border and make the background transparent so that the text looks to be directly inside of the RichTextBox, as desired; however, if you attempt to select only a portion of the text in a "token" and

RichTextBox.RTF setter throwing System.ArgumentException. File format is not valid in Windows version 1803

狂风中的少年 提交于 2020-01-24 20:58:07
问题 The following scenario is simulated to reproduce the crash: Enable Beta: unicode UTF-8 for world wide language support (To enable Start=> Region & Language settings => Related settings -> Additional date, time & regional settings => Region -> Change date, time or number formats => select Administrative tab => Click on Change System Locale. Check Beta: unicode UTF-8 for world wide language support checkbox Restart the system In Windows forms Application => Add a form, RichTextBox, Button and a

How do I load an rtf file to a WPF RichTextBox in Powershell

一世执手 提交于 2020-01-24 15:57:25
问题 Anyone know hoe I can load an rtf file to a wpf RichTextBox? In Windows.Forms I would do this RichTextFile.Loadfile(c:\myfile.rtf) but I don't know how to achieve the same in WPF! Thanks, Ben 回答1: Not sure about PowerShell, but the RichTextBox has a Document property that you use can load a RTF file. Here is sample, plus some good sites that helped me: Some tricks for working with WPF’s RichTextBox WPF RichTextBox WPF RichTextBox: How To Load, Edit and Save Rich Text Format Here is the XAML: