• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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