关于文本框控件的问题

eltl 2008-05-22 10:03:46
我想做这样一个文本框:
默认显示文本框只能显示一行,当文本框内容一行显示不完的时候,自动将文本框的高度扩大,让文本框能显示多行。
当删除时,比如刚刚有三行内容,将第三行删除掉,则文本框的高度应该只能显示二行。
具体怎么设置,或者写什么代码。请大家帮忙!
...全文
45 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cosio 2008-05-24
  • 打赏
  • 举报
回复
Dim l_cnt As Double '记录录入的行数
Dim s_height As Integer '文本框高度
Dim l_updown As Integer '判断增加还是删除

Private Sub Form_Load()
Text1.Text = ""
Let l_cnt = 1
Let s_height = Text1.Height
End Sub

Private Sub Text1_Change()

If Len(Text1) > 0 Then
If l_updown = 0 Then

If Len(Text1) Mod 4 = 0 Then
Let l_cnt = l_cnt + 0.5
Else
If Len(Text1) Mod 4 < 4 Then
Let l_cnt = l_cnt
End If
Text1.Height = s_height * l_cnt
End If

Else
If (Len(Text1) - 1) Mod 4 = 0 Then
Let l_cnt = l_cnt - 0.5
Else
If Len(Text1) Mod 4 < 4 Then
Let l_cnt = IIf(l_cnt > 0, l_cnt, 1)
End If
Text1.Height = s_height * l_cnt
End If

End If
End If
If l_cnt < 1 Then l_cnt = 1
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 8 Then
Let l_updown = 1
Else
Let l_updown = 0
End If
End Sub

__________________
注意点:
1.文本框的长度选择只能录入4个数字,如果是汉字的话,就在修改一下程序
2.设置text1.multiline=true
3.删除字符只考虑回车键的情况
___________________________
只进行简单测试,BUG请回复!

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧