Imports System.ComponentModel
Public Class myrichtextbox
Inherits System.Windows.Forms.RichTextBox
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
Me.Text = ""
End Sub
'UserControl 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Private row As Integer ‘行号
Private row_length As Integer ‘每行最大输入数
<Browsable(True), Description("每行的字符数"), DefaultValue(CByte(10))> _
Public Property set_num() As Integer
Get
Return row_length
End Get
Set(ByVal Value As Integer)
row_length = IIf(Value = 0, 10, Value)
End Set
End Property
Public Function s(ByVal row As Integer) As Integer
If Me.Text.Length = 0 Then Exit Function '如果没有输入时,第一个输入是没有行的
'MessageBox.Show(Me.Text.Length, "111")
'MessageBox.Show(CStr(Me.Text.Length))
If Me.Lines(row).Length >= row_length - 1 Then ‘一般输入9个,第10个为回车符
Return -1
End If
Return 0
End Function
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case &H102 '按键
'MessageBox.Show(111)
Dim KeyAsc As Integer = m.WParam.ToInt32
MessageBox.Show(CStr(KeyAsc))
If s(row) = -1 Then
If Not (KeyAsc = 10 OrElse KeyAsc = 13) Then '按了回车符,换行符是否超行的处理
Return
End If
End If
End Select
MyBase.WndProc(m)
End Sub
Private Sub myrichtextbox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.TextChanged
'MessageBox.Show(Me.Text.Length)
row = Me.Lines.GetLength(0) - 1
End Sub
'Private Sub myrichtextbox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
' MessageBox.Show("哈哈")
'End Sub
End Class