Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Text formatting inside a RichTextox control

On my windows form I have two RichtextBox controls displaying a large amount of text. i want to format some of the words, making them bold, and for some changing font color or size for a paragraph. How can I do that?
ASKER CERTIFIED SOLUTION
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

lucky85, is there a way to make text underlined? Change text font for a paragraph?

I tired using \u \u0 but didn't work
Avatar of YZlat

ASKER

To be honest thos links were not helpful. Too much stuff to go through and I still didn't find anything there. I found some stuff here http://www.pindari.com/rtf1.html

Could you help me with creating a hyperlink in richtextbox?

something equivalent to <a href="http://www.google.com">goole</a>
set the DetectUrls property to true. This should create Hyperlink as soon as you enter some text with http:// and will open with your default browser.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;


namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e) {
            Process.Start(e.LinkText);

        }
        
    }
}

Open in new window

Avatar of YZlat

ASKER

The thing is, I set the text of the RichTextBox the following way:


RichTextBox1.Rtf="{...... http://www.google.com .....}";

How do I make http://www.google.com to show up as hyperlink? No one enters the text into textbox, in fact, it is read-only
Here I made this text as read only and when you hit on the Text Press Here it will be re-directed to google.com as your application needs. You can use that piece of code and modify the text lable.
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
            Process.Start("http://www.google.com");
            MessageBox.Show("Press here!");  
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            linkLabel1.Text = "Press Here";
            linkLabel1.AutoSize = true;
            linkLabel1.Location = this.richTextBox1.GetPositionFromCharIndex(this.richTextBox1.TextLength);
            this.richTextBox1.Controls.Add(linkLabel1);
            this.richTextBox1.AppendText(linkLabel1.Text + "   ");
            this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;
        }

Open in new window

Avatar of YZlat

ASKER

Thanks for your help but my question was not answered completely