well it seems pretty easy ,,,,
if the richtextbox is created the mode is alway insert , if the focus is on
the richtextbox ( carret is there blinking ) and the insert button is
pressed the mode changes to overwrite so trap the messages and you know what
the status is
did some testing ,, and this seems to work fine ( throw a richtextbox on a
form and copy paste below code )
Implements IMessageFilter
Private rtGotfocus As Boolean = True, rtInsert As Boolean = True, rtInsDwn
As Boolean = True
Public Event rtInsertStateChanged(ByVal insert As Boolean)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Application.AddMessageFilter(Me)
AddHandler rtInsertStateChanged, AddressOf rtStateChange
rtStateChange(True)
End Sub
Sub rtStateChange(ByVal insert As Boolean)
Label1.Text = " Status : " & CStr(IIf(insert, " Insert ", " Overwrite "))
End Sub
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) _
As Boolean Implements IMessageFilter.PreFilterMessage
Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) And Keys.KeyCode
If rtGotfocus AndAlso (keyCode = Keys.Insert) Then
If rtInsDwn Then
rtInsert = Not rtInsert
RaiseEvent rtInsertStateChanged(rtInsert)
End If
rtInsDwn = Not rtInsDwn
End If
End Function
Private Sub RichTextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RichTextBox1.GotFocus
rtGotfocus = True
End Sub
Private Sub RichTextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RichTextBox1.LostFocus
rtGotfocus = False
End Sub
End Class