RichTextBox

  • Thread starter Thread starter Guest
  • Start date Start date
Insert Mode ????


i am not sure if i exactly understand what you mean with this ..

however if you mean with this the possibility to enter or copy paste data in
the richtextbox control then it is reading out the ReadOnly property


regards

Michel in Rotterdam ;-)

Michel Posseth ,
 
How can I tell if the Insert Mode is on or off?

No way that I am aware of. I wish you could, and I wish MS would change the
insertion caret so users would know as well. Ditto for ordinary textboxes.
This is an easy thing for MS to do, and many years have gone by with this
suggestion offered by many people.
 
Thanks. I guess one has to track the Insert key and toggle a static or
global variable to track the Insert Key presses. MIcrosoft never was one to
add the finer points to their elementary controls...controls are not one of
their strong points.
 
still don`t understand exactly what you mean :-)


but detecting if the insert key is pressed
can be done with the imessagefilter

i would still like to know what you mean with " Insert Mode is on or off? "
( i might be learning something :-)

regrds

Michel Posseth
 
aha :-)


Most text editors and word processors have two text entry modes from which
you can choose. In insert mode, the editor inserts all characters you type
at the cursor position (or to the right of the insertion point). With each
new insertion, the editor pushes over characters to the right of the cursor
or pointer to make room for the new character.
If insert mode is turned off, the editor overwrites existing characters
instead of inserting the new ones before the old ones. This is often called
overstrike (or overwrite) mode. Most PC keyboards have an Ins key that lets
you switch back and forth between insert and overwrite modes.

For most programs, the default text entry mode is insert mode.




stupid me ,, ofcourse ;-)
 
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
 
Thanks for the code...it's what I needed. However, it would be a lot easier
if M'soft had included a Property in the edit controls that returned the
"Overstrike" mode as True or False and maybe even an "OverstrikeModeChanged"
event. It's a feature that several people have ask for and would seem to be
very trivial for Microsoft to implement in their controls that have edit
features.
 
Indeed it would be a lot easier,,,,

for me it is always a sport to solve problems like this , in some sort of
way i even enjoy it ;-)

By the way with the imessagefilter i could solve lots of problems were in
the past ( VB6 ) i needed to do some fancy API calling or subclassing
i used it the first time for trapping webbrowser events
http://www.freevbcode.com/ShowCode.Asp?ID=5635

Investigate it some more and you will see that you will use this code more
frequent to solve those few things that MS "forgot"

Regards

Michel Posseth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top