PDM add-in task text box

I am developing an task addin for my users. On my custom task setup page I have a multiline text box that I plan to use to change the options available in a listbox on the launch task card. This would allow me to easily change the values available in the listbox without having to rewrite the code to change the listbox items.

The problem is when I am in task setup and I hit enter to create a new line in the textbox, the task setup control treats it as me hitting enter to click the OK button. The print task that comes with the Solidworks Task Add-in has a control that operates the way I would expect but I haven’t been able to figure out the right combination of properties and programming to get what I need.
image.png

I believe there is a property for TextBox controls called AcceptsReturn that you can set to allow it to create a new line when enter is pressed.

I believe this line should get you what you need.

myTextBox.AcceptsReturn = true;

That’s what I initially thought but it doesn’t work.

Okay, I played around with a task add-in and can replicate your issue. I even tried to intercept and cancel the keypress event and was not able to get it to do what you’re looking for. Sorry :neutral_face:

If it’s replicable, might wanna hit up your VAR. Maybe they could cook up a temporary solution for you.

Try playing around with the tab stops (tab order) in your setup form controls? It looks like the “OK” button is still selected/active even though you’re cursor is active in the textbox.

Alternatively, can you add hook to Key Down and/or Up events and swallow the event using KeyPressEventArgs.Handled Property = true; if it’s the enter key to prevent the parent control from using it to “click” the ok button?

I tried intercepting the keypress events but the enter button doesn’t trigger the textbox keypress events before it closes the task setup. I’m thinking of converting this to a listbox with control buttons for adding or removing items from the list. It has the added benefit of having a sort property so I don’t need to sort the list every time I enter a new line.

Seems like a limitation. You can use an alternate approach by using a list and some buttons instead of a text box.


Another approach might be to look for the text box getting focus, and then store the value of the AcceptButton property of the parent Form in a variable and then set the value of the AcceptButton property of the parent Form to ‘null’. When focus is lost on the textbox, set the value of the AcceptButton property of the parent Form to the stored variable.