Skip to main content

When Editing data in a text box, how can the Insert key toggle between Insert and Overwrite. It seems to be stuck in Insert mode. This is during execution not design.

I Have a check box on my form. It takes two mouse clicks to change the state of the check box. One to gain focus and the other to change the state. How can I set it up so that it only takes one mouse click?

When Editing data in a text box, how can the Insert key toggle between Insert and Overwrite. It seems to be stuck in Insert mode. This is during execution not design.

I Have a check box on my form. It takes two mouse clicks to change the state of the check box. One to gain focus and the other to change the state. How can I set it up so that it only takes one mouse click?

For the checkbox issue, I believe that something else on your form is interferring with the behavior here as the default is to check the box as soon as it is clicked.

Try creating a new form with a checkbox on it and you will see that it behaves correctly.
Perhaps some other event like mouseClick is being trapped on the form and handled?

For the TextBox issue:

A standard Windows Forms TextBox control does not support an Overwrite mode by default.
A MaskedTextBox control does have a property called InsertKeyMode which can be set to Insert or Overwrite depending on your needs.

I found an example of how to implement the insert/overwrite toggle within a standard TextBox and I have converted it to COBOL as follows:

       class-id testinsertmode.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       01 insert-mode   condition-value value true.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id textBox1_KeyPress final private.
       
       procedure division using by value sender as object e as type System.Windows.Forms.KeyPressEventArgs.
           
           if insert-mode
              exit method
           else
              if textBox1::SelectionStart < textBox1::TextLength and Not type Char::IsControl(e::KeyChar)
                 declare SaveSelectionStart as binary-long = textBox1::SelectionStart
                 declare sb = new type StringBuilder(textBox1::Text)
                 set sb[textBox1::SelectionStart] to e::KeyChar
                 set textBox1::Text to sb::ToString
                 set textBox1::SelectionStart to SaveSelectionStart   1
                 set e::Handled to true
              end-if
           end-if.
           
       end method.

       method-id textBox1_KeyDown final private.
       procedure division using by value sender as object e as type System.Windows.Forms.KeyEventArgs.
           if e::KeyData = type Keys::Insert and insert-mode
              set insert-mode to false
           else
              if e::KeyData = type Keys::Insert and not insert-mode
                 set insert-mode to true
              end-if
           end-if
           
       end method.

       end class.

When Editing data in a text box, how can the Insert key toggle between Insert and Overwrite. It seems to be stuck in Insert mode. This is during execution not design.

I Have a check box on my form. It takes two mouse clicks to change the state of the check box. One to gain focus and the other to change the state. How can I set it up so that it only takes one mouse click?

Thank You, This worked Great. Just what I wanted.


When Editing data in a text box, how can the Insert key toggle between Insert and Overwrite. It seems to be stuck in Insert mode. This is during execution not design.

I Have a check box on my form. It takes two mouse clicks to change the state of the check box. One to gain focus and the other to change the state. How can I set it up so that it only takes one mouse click?

Thank You, This worked Great. Just what I wanted.