How Can Transferdata from RitchTextBox to Label with all Formats. i.e RitchTextBox's Text Color ,Font,FontStyle

Recommended Answers

All 6 Replies

For color make your label's forecolor equal the richtextbox's forecolor. Do the same with the Font property and it will include Bold,Italic,Underline,Strikethrough,etc.

@tinstaafl
Ihave already do that

label1.text = RitchTextBox1.text;
Label1.ForeColor = RitchTextBox1.ForeColor
Label1.Font = RitchTextBox1.Font;

But It Could not Work.Text show in label but it font and color doesn't show.Please Help

You might have to show more of your code, that code works fine for me, and try as I might I can't break it so it doesn't work.

 //Write/Save File as RichText 
  private void btnwrite_Click(object sender, EventArgs e)
        {

            richTextBox1.ForeColor = Color.Red;
            richTextBox1.Font = new Font(richTextBox1.Font, FontStyle.Bold);
            richTextBox1.SaveFile(@"D:/myFile.rtf", RichTextBoxStreamType.RichText);
        }
        // Read File from D Drive as RichText
 private void btnRead_Click(object sender, EventArgs e)
        {
            richTextBox2.LoadFile(@"D:/myFile.rtf", RichTextBoxStreamType.RichText);

        }
        //Show RichText in Label
                           // Here is Problem I show text but not forecolor and not font
         private void btnshowtext_Click(object sender, EventArgs e)
        {


            label1.Text = richTextBox2.Text;
            label1.ForeColor = richTextBox2.ForeColor;
            label1.Font = richTextBox2.Font;
        }

I hope You Understood my Problem Please Help

What's happening is the richtextbox isn't taking on the characteristics of the text when you load it from a file. The secret is to select all the text then you can read selection font and selection color:

            richTextBox2.SelectAll();
            label1.Font= richTextBox2.SelectionFont;
            label1.ForeColor = richTextBox2.SelectionColor;
            label1.Text = richTextBox2.Text;

and eureka :)

@tinstaafl
Ok Thank You Very Much for Given Me Time And Solved My Problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.