怎样限制RichTextBox输入

thw19850316 2008-03-03 11:52:21
怎样限制RICHTEXTBOX输入的长度,内容包括中文,英文,数字等其他字符,也可以包括图片,但是输入不能超过RICHTEXTBOX的宽度(RICHTEXTBOX.WIDTH固定),怎样做?请高手帮忙,谢谢!
...全文
257 点赞 收藏 24
写回复
24 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
thw19850316 2008-03-07
呵呵,是的
麻烦你了!
回复
cbm6666 2008-03-06
如果只有设定并判断 "每一行" 的各别总字数与符号等不能超过设定的宽度那就很简单了,

有图片的话, 这个文档肯定是 .rtf 因为只有 .rtf 才能存图,理论上难度不大, 明天我试着做看,今天太晚了.

回复
fengkoulangjian 2008-03-06
学习~
回复
cbm6666 2008-03-06
哎,晕倒了,一个图片插入文字里面,不管图多大也只占一个字符, 怎么会这样呢 ?

要换个思路用光标位置了.


回复
thw19850316 2008-03-06
好的,没关系!
回复
cbm6666 2008-03-06
呵呵...没有十足的把握, Richtextbox也不常用,吃完饭就试看吧.



回复
thw19850316 2008-03-06
[Quote=引用 18 楼 cbm666 的回复:]
如果只有设定并判断 "每一行" 的各别总字数与符号等不能超过设定的宽度那就很简单了,

有图片的话, 这个文档肯定是 .rtf 因为只有 .rtf 才能存图,理论上难度不大, 明天我试着做看,今天太晚了.
[/Quote]

就是一行了,呵呵,谢谢啊!
回复
thw19850316 2008-03-05
等了我好几天了啊。。。
回复
thw19850316 2008-03-05
等待中。。。
回复
沙漠GTS 2008-03-04
protected override void WndProc(ref System.Windows.Forms.Message m)
{}
中間用正則表達式判斷
回复
thw19850316 2008-03-04
Private Sub TrueLength
Dim ret As Long
Dim intStart As Integer, intEnd As Integer, intStartX As Integer, intEndX As Integer

txtTotal.SelStart = 0
txtTotal.SelLength = Len(txtTotal.Text)

ret = SendMessage(txtTotal.hWnd, EM_GETSEL, 0, 0)
intStart = ret And 65535
intEnd = (ret And &HFFFF0000) / (2 ^ 16)
ret = SendMessage(txtTotal.hWnd, EM_POSFROMCHAR, intStart, 0)
intStartX = ret And 65535
ret = SendMessage(txtTotal.hWnd, EM_POSFROMCHAR, intEnd + 1, 0)
intEndX = ret And 65535
length = intEndX - intStartX
End Sub
这段代码可以得到实际宽度,但是放到Keypress事件中就不行了,
txtTotal.SelStart = 0
txtTotal.SelLength = Len(txtTotal.Text),因为这两句导致只能输入一个字符

回复
俺用richecit做不到
回复
thw19850316 2008-03-04
哦,那是否可以用RICHTEXT做到啊?
回复
写示例的时候是用的text,测试正常,换成了richedit发现richedit的字符是可以随意的,所以不正确了,跟是否中文无关的。
回复
thw19850316 2008-03-04
[Quote=引用 14 楼 superwat 的回复:]
protected override void WndProc(ref System.Windows.Forms.Message m)
{}
中間用正則表達式判斷
[/Quote]

不会,可以帮我写出来吗?谢谢!
回复
单行还是多行?
回复
thw19850316 2008-03-03
中文不行啊
回复
那就是vb6的。
回复
thw19850316 2008-03-03
上面是vb.net,用VB6如何写啊?
回复
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ExtTextOut Lib "gdi32" Alias "ExtTextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal wOptions As Long, ByVal lpRect As Any, ByVal lpString As String, ByVal nCount As Long, lpDx As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Form_Load()
Me.Font = "宋体"
Text1.Font = "宋体"

Me.FontSize = 12
Text1.FontSize = 12

Text1.Text = ""

End Sub

Private Sub Text1_Change()
Dim l As Long
Dim w As Long
Dim textsize As POINTAPI
l = LenB(StrConv(Text1.Text, vbFromUnicode))
w = GetTextExtentPoint32(Me.hdc, Text1.Text, l, textsize)
If l * textsize.X > Text1.Width Then
Text1.Text = Mid(Text1.Text, 1, Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
End If
End Sub
回复
加载更多回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-03 11:52
社区公告
暂无公告