怎样设置winform的文本框行高
1个回答
展开全部
其中有段代码:
用API计算行数,然后在TextChanged中动态改变其客户区的大小:
假设你的文本框为textBox2
[DllImport("user32.dll", EntryPoint="SendMessageA")]
private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
int EM_GETLINECOUNT = 0x00BA;//获取总行数的消息号
int lc = SendMessage(this.textBox2.Handle,EM_GETLINECOUNT,IntPtr.Zero,"");
int sf = this.textBox2.Font.Height * lc;
this.textBox2.ClientSize = new Size(this.textBox2.ClientSize.Width,sf + 5);
}
用API计算行数,然后在TextChanged中动态改变其客户区的大小:
假设你的文本框为textBox2
[DllImport("user32.dll", EntryPoint="SendMessageA")]
private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
int EM_GETLINECOUNT = 0x00BA;//获取总行数的消息号
int lc = SendMessage(this.textBox2.Handle,EM_GETLINECOUNT,IntPtr.Zero,"");
int sf = this.textBox2.Font.Height * lc;
this.textBox2.ClientSize = new Size(this.textBox2.ClientSize.Width,sf + 5);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |