using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace RtfSizingTestApp { public class Form1 : Form { public Form1() { Size proposedSizeRich = new Size(700, 0); InitializeComponent(); { string rtfTextWithLine = "{\\rtf1\\ansi line1\\line line2}"; rtbWithLine.Rtf = rtfTextWithLine; Size preferredSize = rtbWithLine.GetPreferredSize(proposedSizeRich); rtbWithLine.Size = preferredSize; } { string rtfTextWithPar = "{\\rtf1\\ansi line1\\par line2}"; rtbWithPar.Rtf = rtfTextWithPar; Size preferredSize = rtbWithPar.GetPreferredSize(proposedSizeRich); rtbWithPar.Size = preferredSize; } } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Text = "Form1"; rtbWithLine = new System.Windows.Forms.RichTextBox(); rtbWithLine.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); rtbWithLine.Dock = System.Windows.Forms.DockStyle.None; rtbWithLine.Location = new System.Drawing.Point(10, 10); rtbWithLine.Size = this.ClientSize; rtbWithPar = new System.Windows.Forms.RichTextBox(); rtbWithPar.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); rtbWithPar.Dock = System.Windows.Forms.DockStyle.None; rtbWithPar.Location = new System.Drawing.Point(10, 200); rtbWithPar.Size = this.ClientSize; this.Controls.Add(rtbWithLine); this.Controls.Add(rtbWithPar); } private System.Windows.Forms.RichTextBox rtbWithLine; private System.Windows.Forms.RichTextBox rtbWithPar; } }