내용에 따라서 자동으로 크기가 변하는 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;
}
}
}
'Code > C#' 카테고리의 다른 글
| AxWebBrowser.ReadyState 샘플코드 (0) | 2008.04.16 |
|---|---|
| WebBrowser.ReadyState 샘플코드 (0) | 2008.04.11 |
| iTextSharp 샘플코드 - Hello World (0) | 2008.04.08 |
| [C#] Object Initializer 사용법 샘플 코드 (0) | 2008.02.11 |
| [C#] 간단한 Object Initializer 샘플 코드 (0) | 2008.02.11 |