티스토리 뷰

Code/C#

RichTextBox AutoResize 샘플코드

Hide Code 2008. 4. 8. 13:28
내용에 따라서 자동으로 크기가 변하는 RichTextBox 샘플코드이다.

The key is handling the ContentsResized event on the RichTextBox (doesn't exist on a TextBox).
The ContentsResizedEventArgs has a NewRectangle property which will give you the desired size.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RichTextBoxAutoResizeSample
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }
       
       private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)
       {
           this.richTextBox1.Height = e.NewRectangle.Height + 5;
       }
   }
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함