Highlighted
Honored Contributor.
Honored Contributor.
2835 views

winforms textbox cursor / caret positioning for data field / file maintenance

Jump to solution

Question for Chris Glazier , et al... 

Either I am confused or Managed WinForms COBOL seems to present some unique aspects perhaps not normally found in other .NET or OOP languages, due to the possibility of a mix of COBOL's tradition of fixed-length fields ( example: CONTACT PIC X(30) ) along with the aspect of variable length strings, winforms textbox controls, etc.

Scenario:  A winforms-with-textboxes file maintenance program used to maintain a traditional COBOL Indexed file which has fixed-length fields.

Look at your shareData example program (although it doesn't use a file, it is an example of doing maintenance to fixed length fields via winforms textboxes).

Let's say you had a similar maintenance program using this/these screens to do maintenance against existing records already in the file.  Once you bring the existing record up and show the fields in textboxes, you would be allowed to make changes to the fields (and the record would be rewritten the file, etc.).

Question1:  In this scenario, where would you want the cursor / caret / insertion position to be initially located within the textbox showing the existing data field ???

Answer:  I submit that you would want it to be located to the immediate right of the right-most non-space character.  (as a weak 2nd choice, have it located at the very front of the field in front of the 1st character.

Question 2:  Looking again at shareData and how it currently (and undesirably) behaves in this regard... Is there some known way to do this? (have the cursor / caret / insertion position positioned to the immediate right of the right-most non-space character of the existing field displayed in the textbox)?

Thanks

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: winforms textbox cursor / caret positioning for data field / file maintenance

Jump to solution

The .NET controls used in a COBOL Winform application are the same controls used in a C# or VB Winforms application as they all use the underlying .NET Framework class assemblies. The behavior in COBOL is no different than the behavior in C#.

I do not see the demo program that you reference. Can you please attach it?

You can explicitly set the cursor position within a textbox by using the SelectionStart and SelectionLength properties of the TextBox class.

The following example will set the cursor position to the end of the field when focus is given to the control.

          set textBox1::Text to "ABCDE"

          set textBox1::SelectionStart to textBox1::Text::Count

          set textBox1::SelectionLength to 0

          invoke textBox1::Focus

You should probably google the term "winform textbox cursor position" and see what it comes up with as there are a number of different caveats to this depending on how you enter the textbox controls on your form.

Thanks.

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: winforms textbox cursor / caret positioning for data field / file maintenance

Jump to solution

The demo program... It's the wiki article "Share data between multiple Windows Forms programs using EXTERNAL" dated 14 Aug 2012 and it has the shareData.zip attached.  Here's the link:

community.microfocus.com/.../19903.share-data-between-multiple-windows-forms-programs-using-external.aspx

First, run this program as is.  The point that I am trying to make is this:

1. In the file-maintenance-of-existing-data scenario I described earlier, you would probably be initially populating a textbox using the contents of a fixed length field described as say, PIC X(30).  This data would be coming from an existing record on the file.  When you do this, you will be populating textBox1::Text with a value of "ABCDE_________________________" , i.e., all 30 characters.  Assuming you don't do something like you described above, when the textbox is then presented to the user, the cursor / caret / insert position will not be in an optimum or desirable position.

Similar to your reply above, I came up with the following:

When initially populating the textbox and just prior to presenting the data to the user, instead of the:

          set txtContact::Text to contact

you would have something like this:

          set txtContact::Text to contact::TrimEnd(' ')

          set txtContact::SelectionStart to txtContact::Text::Length

          set txtContact::SelectionLength = 0

which is similar to what you had described.

Thanks

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: winforms textbox cursor / caret positioning for data field / file maintenance

Jump to solution

The .NET controls used in a COBOL Winform application are the same controls used in a C# or VB Winforms application as they all use the underlying .NET Framework class assemblies. The behavior in COBOL is no different than the behavior in C#.

I do not see the demo program that you reference. Can you please attach it?

You can explicitly set the cursor position within a textbox by using the SelectionStart and SelectionLength properties of the TextBox class.

The following example will set the cursor position to the end of the field when focus is given to the control.

          set textBox1::Text to "ABCDE"

          set textBox1::SelectionStart to textBox1::Text::Count

          set textBox1::SelectionLength to 0

          invoke textBox1::Focus

You should probably google the term "winform textbox cursor position" and see what it comes up with as there are a number of different caveats to this depending on how you enter the textbox controls on your form.

Thanks.

View solution in original post

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: winforms textbox cursor / caret positioning for data field / file maintenance

Jump to solution

The demo program... It's the wiki article "Share data between multiple Windows Forms programs using EXTERNAL" dated 14 Aug 2012 and it has the shareData.zip attached.  Here's the link:

community.microfocus.com/.../19903.share-data-between-multiple-windows-forms-programs-using-external.aspx

First, run this program as is.  The point that I am trying to make is this:

1. In the file-maintenance-of-existing-data scenario I described earlier, you would probably be initially populating a textbox using the contents of a fixed length field described as say, PIC X(30).  This data would be coming from an existing record on the file.  When you do this, you will be populating textBox1::Text with a value of "ABCDE_________________________" , i.e., all 30 characters.  Assuming you don't do something like you described above, when the textbox is then presented to the user, the cursor / caret / insert position will not be in an optimum or desirable position.

Similar to your reply above, I came up with the following:

When initially populating the textbox and just prior to presenting the data to the user, instead of the:

          set txtContact::Text to contact

you would have something like this:

          set txtContact::Text to contact::TrimEnd(' ')

          set txtContact::SelectionStart to txtContact::Text::Length

          set txtContact::SelectionLength = 0

which is similar to what you had described.

Thanks

View solution in original post

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.