C# 文本框问题 我想请教一下如何判断textbox文本框内文本长度是否超出文本框的可见长度,便于当文本超出时自动增大文本框的长度?谢谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><head><title>文字字段自动调整大小</title><script language="javascript"><!-- function autoWidth(){ str = form1.name.value; len = str.length; if (len != 0 ){ form1.name.size = len; } }//--></script></head><body><form name="form1">姓名:<input type="text" name="name" onKeyPress="autoWidth()" size=1></form></body></html>看看这个应该对你有帮助 private void textBox1_TextChanged(object sender, EventArgs e) { //textBox1.Text.Length } private void textBox1_TextChanged(object sender, EventArgs e) { Graphics g = this.textBox1.CreateGraphics(); System.Drawing.SizeF s = g.MeasureString(this.textBox1.Text, this.textBox1.Font); this.textBox1.Width = (int)s.Width + 3; } 如何编程引用本地rdlc报表中的某列? foreach 循环的奇怪问题 怎么获得屏幕背景颜色?比如对话框的颜色! 如何判断一个字符串不是整数? 如何读取一个文件夹中各文件的内容啊? xml的读取添加问题 (解决就揭帖) c#中的usercontrol这样用? 怎么判断一个变量里的值是否在一个数组中? c# winform里面listview添加完数据后怎么进行筛选功能? 求助webbrowser如何使选中的标签改变背景色 string操作 考考你的反应能力 dataGridView1如何设置整行的颜色
<head>
<title>文字字段自动调整大小</title>
<script language="javascript">
<!--
function autoWidth(){
str = form1.name.value;
len = str.length;
if (len != 0 ){
form1.name.size = len;
}
}
//-->
</script>
</head>
<body>
<form name="form1">
姓名:
<input type="text" name="name" onKeyPress="autoWidth()" size=1>
</form>
</body>
</html>看看这个应该对你有帮助
{
//textBox1.Text.Length
}
{
Graphics g = this.textBox1.CreateGraphics();
System.Drawing.SizeF s = g.MeasureString(this.textBox1.Text, this.textBox1.Font);
this.textBox1.Width = (int)s.Width + 3;
}