首页  编辑  

TextBox高度自适应

Tags: /C#/界面处理/TextBox_RichEdit/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "User32.dll" )]

static extern int SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam);

private const int EM_GETLINECOUNT = 0x00BA ;

private void textBox1_TextChanged( object sender , EventArgs e)

{

    int vCount = SendMessage(textBox1 . Handle, EM_GETLINECOUNT, 0 , 0 );

   textBox1 . Height = (textBox1 . Font . Height - 2 ) * vCount + 8 ;              

}