public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//注意空行也是行
MessageBox.Show(this.textBoxEx1.LineCount.ToString());
}
}
//试试这个自定义TextBoxEx
public class TextBoxEx : TextBox
{
private const int EM_GETLINECOUNT = 0xBA;
public int LineCount
{
get
{
Message msg = Message.Create(this.Handle, EM_GETLINECOUNT, IntPtr.Zero, IntPtr.Zero);
base.DefWndProc(ref msg);
return msg.Result.ToInt32();
}
}
}