6 Replies - 7336 Views - Last Post: 27 August 2009 - 10:41 AM Rate Topic: -----

#1 avani@swayamsoftware.com  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 02-June 09

Bold effect in rtf file

Posted 26 August 2009 - 10:41 PM

Hi,

I have to write an application that generates an rtf file. Some parts of the this file must be bold.

What should I do in order to have a string (using c#) be represented bold in the t file?

Thanks,
Is This A Good Question/Topic? 0
  • +

Replies To: Bold effect in rtf file

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Bold effect in rtf file

Posted 27 August 2009 - 12:18 AM

You have to learn how the RTF file is organized, and if you do not have a visual editor, then you will need to create the RTF the "low-level" way, therefore directly implementing the formatting.

For some reference, take a look here.
Was This Post Helpful? 0
  • +
  • -

#3 avani@swayamsoftware.com  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 02-June 09

Re: Bold effect in rtf file

Posted 27 August 2009 - 01:00 AM

Actually i had already implement one code usig \b \b0 options but it doesnt create any different in my output.
StringBuilder builder = new StringBuilder();
			//Add the header.
		   
			builder.Append(@"{\rtf1\fbidis\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}" + "\r\n");
			builder.Append(@"{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fnil\fcharset0 Microsoft Sans Serif;}}" + "\r\n");
			builder.Append(@"{\colortbl;\red0\green0\blue0;}" + "\r\n");
			builder.Append("\r\n");

string header = "Title";

header = string.Format(@"\b {0}\b0", header);

builder.Append(hearder);

richtextbox.rtf = builder.ToString();


Was This Post Helpful? 0
  • +
  • -

#4 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Bold effect in rtf file

Posted 27 August 2009 - 01:11 AM

yes core have given you a good stuff you must see that.any way you asked how to do it in C# it could be done using Font class
Ok try to understand what I am doing ,First in C# create a windows application then on the form add a richtextbox and add this text from properties window " We are in DreamInCode " then go to the form load event and add this code.
 //Create a Font to set the selected text font
			Font font = new Font("Arial", 8,FontStyle.Bold);
			//Select the text
			richTextBox1.Find("DreamInCode");
			//Set the font
			richTextBox1.SelectionFont = font;
			//Save it in *.rtf format
			richTextBox1.SaveFile("C:\\mytext.rtf");



Hope you will get some idea from this code
Was This Post Helpful? 0
  • +
  • -

#5 avani@swayamsoftware.com  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 02-June 09

Re: Bold effect in rtf file

Posted 27 August 2009 - 02:08 AM

Thank you.

Its realy being help to me . Thakns a lot.
Was This Post Helpful? 0
  • +
  • -

#6 avani@swayamsoftware.com  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 02-June 09

Re: Bold effect in rtf file

Posted 27 August 2009 - 03:14 AM

Debjit Can you please give me some glims how to add new blank line in rich text box ?
Was This Post Helpful? 0
  • +
  • -

#7 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Bold effect in rtf file

Posted 27 August 2009 - 10:41 AM

In MSDN you will find every thing about RichTextBox.And for adding a new line use special characters in a string by using escape sequences,like "\n" for newline
richTextBox1.Text = "In DreamInCode\n";
richTextBox1.Text += "\n";//Adding a new blank line 
richTextBox1.Text += "Hope you got it";//Adding a new text



Good luck

This post has been edited by debjit625: 27 August 2009 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1