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;
}
}
}
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;
}
}
}