首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MemoEdit (DevExpress)中的限制长度(字符输入)

MemoEdit (DevExpress)中的限制长度(字符输入)
EN

Stack Overflow用户
提问于 2014-03-05 15:18:55
回答 2查看 2.2K关注 0票数 2

我使用以下代码(基于devexpress帮助论坛)来防止用户放弃更多的代码,而不是48 charactersMemoEdit中的一行

代码语言:javascript
运行
复制
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:**的注记

代码语言:javascript
运行
复制
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-服务的计算机输入不等。

EN

Stack Overflow用户

发布于 2014-03-05 16:14:14

使用标准的winform,可以通过处理KeyDown事件、查找Ctrl + V键和检查Cliboard文本来实现这一点。

代码语言:javascript
运行
复制
Private Sub txtAuthors_KeyDown(sender As Object, e As KeyEventArgs) Handles txtAuthors.KeyDown
    If ((e.Modifiers = Keys.Control) AndAlso (e.KeyCode = Keys.V)) Then
        Dim text As String = My.Computer.Clipboard.GetText()
        If (text.Length > 48) Then
            My.Computer.Clipboard.SetText(text.Substring(0, 48))
        End If
    End If
End Sub

注意:我没有安装devexpress,所以我不能保证这将适用于MemoEdit控件。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22201786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档