Highlighted
Absent Member.
Absent Member.
1229 views

Insert Key

Jump to solution

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?

Jerry

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

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.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

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.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

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

Jerry

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.