如何防止 MaxLength 发出哔哔声或完全防止应用程序发出哔哔声? [英] How do I prevent MaxLength beeping or prevent application beeping altogether?
本文介绍了如何防止 MaxLength 发出哔哔声或完全防止应用程序发出哔哔声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当达到我的文本框的 MaxLength
时,会产生哔声.我想防止这种蜂鸣声,甚至可以防止我的应用程序的所有蜂鸣声实例(如果可以实现).
When my text box's MaxLength
is reached, a beep sound is produced. I want to prevent this beeping and would even go so far as preventing all instances of beeping for my application if achievable.
我已经熟悉如何使用 Substring
模仿 MaxLength
并重置插入符号,但在这种特殊情况下,替换 MaxLength
不是一个选项.
I'm already familiar with how to mimic MaxLength
using Substring
and resetting the caret but in this particular instance, substituting MaxLength
is not an option.
- 在 Visual Studio 中,在设计模式下,将文本框拖动到新表单上.
- 按原样使用以下内容:
代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.MaxLength = 5
End Sub
Private Sub TextBox1_keypress(keyascii As Integer)
If len(TextBox1.text) = 5 Then
keyascii = 0
End If
End Sub
End Class
以上是我在网上看到的例子的改编,但没有效果.
The above is an adaptation of examples I've come across online but has no effect.
推荐答案
测试这个:
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not e.KeyChar.Equals(ControlChars.Back) Then
If Me.TextBox1.TextLength = Me.TextBox1.MaxLength Then
e.Handled = True
End If
End If
End Sub
这篇关于如何防止 MaxLength 发出哔哔声或完全防止应用程序发出哔哔声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文