richtextbox

Dynamically adding hyperlinks to a RichTextBox

萝らか妹 提交于 2019-11-30 08:58:50
I'm trying to dynamically add some hyperlinks to a RichTextBox using WPF and C# but am not having much success. My code is summarised below: FlowDocument doc = new FlowDocument(); richTextBox1.Document = doc; richTextBox1.IsReadOnly = true; Paragraph para = new Paragraph(); doc.Blocks.Add(para); Hyperlink link = new Hyperlink(); link.IsEnabled = true; link.Inlines.Add("Hyperlink"); link.NavigateUri = new Uri("http://www.google.co.uk"); link.Click += new RoutedEventHandler(this.link_Click); para.Inlines.Add(link); .... protected void link_Click(object sender, RoutedEventArgs e) { MessageBox

How to make some text bold in a rich text box in C#

﹥>﹥吖頭↗ 提交于 2019-11-30 08:48:52
I want to create a text editor where I can make text bold, change its color, etc. I found this code to approximately work: public static void BoldSelectedText(RichTextBox control) { control.SelectionFont = new Font(control.Font.FontFamily, control.Font.Size, FontStyle.Bold); } But when I type in more letters in the RichTextBox the text is still bold. How can I make it so that only the selected text is bold and the next characters aren't unless I select the text and hit the "Make Bold" button? You should set the font after the selection to the original font. If you want you can save the

Links inside rich textbox?

馋奶兔 提交于 2019-11-30 08:05:39
I know that richtextboxes can detect links (like http://www.yahoo.com ) but is there a way for me to add links to it that looks like text but its a link? Like where you can choose the label of the link? For example instead of it appearing as http://www.yahoo.com it appears as Click here to go to yahoo edit: forgot, im using windows forms edit: is there something thats better to use (as in easier to format)? Mario Fraiß Of course it is possible by invoking some WIN32 functionality into your control, but if you are looking for some standard ways, check this post out: Create hyperlink in TextBox

Broken hyperlinks in RTF file in RichTextBox

六眼飞鱼酱① 提交于 2019-11-30 07:31:42
问题 I'm using a RichTextBox to display an RTF file, which includes a single hyperlink. The link text is not a URL (the target is a valid URL). The RTF was created with Word. Both Word and WordPad properly recognize the links (WordPad does not launch the links, but shows the appropriate hand cursor). When I load the RTF into a RichTextBox the links appear formatted correctly (blue and underlined), but rather than behaving like a link, when the cursor moves over the link it remains an I-beam, the

C# FlowDocument to HTML conversion

时光总嘲笑我的痴心妄想 提交于 2019-11-30 07:25:34
Basically, I have a RichTextBox and I want to convert the formatted contents of it to HTML so it can be sent as an email. The method I am currently using does not give any formatting at all: string message = new TextRange(messageTextBox.Document.ContentStart, messageTextBox.Document.ContentEnd).Text; So I searched around and found this , however, it is over 5 years old and in the comments an MSFT user has commented saying that it is no longer supported - "This sample has been removed from our sample set and is no longer supported" , and the HTML it generates is in an older format than modern

RichTextBox color selected lines

谁说胖子不能爱 提交于 2019-11-30 07:08:26
I am new to windows Forms. I am using VS 2008, C# to write a RichTextBox. I want to be able to color each line with a different color as I write to the RichTextBox. Can someone point me to samples. Thanks foreach (string file in myfiles) { // As I process my files // richTextBox1.Text += "My processing results"; if(file == "somefileName") { // Color above entered line or enter new colored line } } Set SelectionColor before you append, something like: int line = 0; foreach (string file in myfiles) { // Whatever method you want to choose a color, here // I'm just alternating between red and blue

WPF RichTextBox with no width set

﹥>﹥吖頭↗ 提交于 2019-11-30 06:43:05
问题 I have the following XAML code: <Window x:Class="RichText_Wrapping.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1"> <Grid> <RichTextBox Height="100" Margin="2" Name="richTextBox1"> <FlowDocument> <Paragraph> This is a RichTextBox - if you don't specify a width, the text appears in a single column </Paragraph> </FlowDocument> </RichTextBox> </Grid> ... If you create this window in XAML, you can

WPF Richtextbox FontFace/FontSize

て烟熏妆下的殇ゞ 提交于 2019-11-30 05:47:25
问题 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,

Show LineNumbers from the RichTextBox in WPF

好久不见. 提交于 2019-11-30 05:33:21
I found an example, how to show the LineNumbers from a RichTextBox in Windows Forms. http://www.codeproject.com/Articles/38858/Line-Numbers-for-RichText-Control-in-C Have somebody an example for it in WPF ? Edit: Does someone have work with AvalonEdit, because he wanted to show LineNumbers in his Programm and can help me by my Problem. I thought just to add a simple solution... Avalon ( Download ) has been mentioned, here is how to do row lines with it: <avalon:TextEditor ShowLineNumbers="True" Width="500" Height="500" Text="some more test some more test some more test some more test some

RichTextBoxAppender using log4net

只愿长相守 提交于 2019-11-30 05:32:23
Is there a way to programatically create a RichTextBoxAppender using log4net? In other words no xml app.config? using System; using System.Windows.Forms; using System.Drawing; using log4net; using log4net.Core; using log4net.Appender; using log4net.Util; namespace Vip.Logging { /// <summary> /// Description of RichTextBoxAppender. /// </summary> public class RichTextBoxAppender : AppenderSkeleton { #region Private Instance Fields private RichTextBox richTextBox = null; private Form containerForm = null; private LevelMapping levelMapping = new LevelMapping(); private int maxTextLength = 100000;