0

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

2
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by yousafc#
Featured Replies
  • 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 :) Read More

0

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.

0

@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

0

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.

0
 //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

1

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 :)

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.