• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

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?
0
YZlat
Asked:
YZlat
  • 4
  • 4
1 Solution
 
Anil GolamariCommented:
You can use something like this

richTextBox1.Rtf = @"{\rtf1\ansi Example to make the char's in a string as \b bold\b0.}";
0
 
YZlatAuthor Commented:
lucky85, is there a way to make text underlined? Change text font for a paragraph?

I tired using \u \u0 but didn't work
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
YZlatAuthor Commented:
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>
0
 
Anil GolamariCommented:
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

0
 
YZlatAuthor Commented:
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
0
 
Anil GolamariCommented:
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

0
 
YZlatAuthor Commented:
Thanks for your help but my question was not answered completely
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now