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 FitRichTextBox
{
    public partial class frm55FitRichTextBox : Form
    {
        public frm55FitRichTextBox()
        {
            InitializeComponent();
        }

        // Don't let the RichTextBox wrap long lines.
        private void frm55FitRichTextBox_Load(object sender, EventArgs e)
        {
            contentsRichTextBox.WordWrap = false;
            contentsRichTextBox.ScrollBars = RichTextBoxScrollBars.None;
        }

        // Make the RichTextBox fit its contents.
        private void contentsRichTextBox_ContentsResized(object sender, ContentsResizedEventArgs e)
        {
            const int margin = 5;
            RichTextBox rch = sender as RichTextBox;
            rch.ClientSize = new Size(
                e.NewRectangle.Width + margin,
                e.NewRectangle.Height + margin);
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.contentsRichTextBox = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // contentsRichTextBox
            // 
            this.contentsRichTextBox.BackColor = System.Drawing.SystemColors.Window;
            this.contentsRichTextBox.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.contentsRichTextBox.Location = new System.Drawing.Point(12, 12);
            this.contentsRichTextBox.Name = "contentsRichTextBox";
            this.contentsRichTextBox.Size = new System.Drawing.Size(50, 50);
            this.contentsRichTextBox.TabIndex = 1;
            this.contentsRichTextBox.Text = "";
            this.contentsRichTextBox.ContentsResized += new System.Windows.Forms.ContentsResizedEventHandler(this.contentsRichTextBox_ContentsResized);
            // 
            // frm55FitRichTextBox
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 111);
            this.Controls.Add(this.contentsRichTextBox);
            this.Name = "frm55FitRichTextBox";
            this.Text = "FitRichTextBox";
            this.Load += new System.EventHandler(this.frm55FitRichTextBox_Load);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.RichTextBox contentsRichTextBox;
    }
}