【发布时间】:2014-04-07 17:58:36
【问题描述】:
我正在使用以下代码(基于devexpress 帮助论坛)来防止用户在48 characters 中提供更多MemoEdit 中的一行
Private Sub txtAuthors_EditValueChanging(sender As System.Object, e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles txtAuthors.EditValueChanging
If e.NewValue Is Nothing Then
'No Value found in memoEditor
Return
End If
'Max lenght of textbox
Dim maxLength As Integer = 48
Dim edit As DevExpress.XtraEditors.MemoEdit = TryCast(sender, DevExpress.XtraEditors.MemoEdit)
For Each str As String In edit.Lines
If str.Length > maxLength Then
e.Cancel = True
Return
End If
Next str
End Sub
此功能可防止插入超过 48 个字符的字符串。但我真正希望实现的是:
我的目标:
如果用户使用more than 48 chars 输入新字符串(使用Ctrl + V/Paste)。它不应阻止输入所有数据。控件应除the first 48 chars 之外的其余部分。
如何实现这种行为。我试图操纵e.NewValue,但无济于事......
关于Lines-property 的备注:
You are not able to use the Lines property to change a particular array's element
directly. Instead, you should read the Lines property to get the array, change
the required array's element and then assign the array back to Lines.
注意:我读过这篇文章 (Limit the input length of a DevExpress TextEdit and MemoEdit controls),但没有帮助
注意 2: MemoEdit 中的输入可能会有所不同,从普通用户输入(按任意键或Ctrl + V)到来自 WCF 服务的基于计算机的输入
【问题讨论】:
标签: .net vb.net winforms devexpress