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