PDM add-in task text box
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.
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.
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.
Go to full postRe: PDM add-in task text box
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.
I believe this line should get you what you need.
Code: Select all
myTextBox.AcceptsReturn = true;
Re: PDM add-in task text box
That's what I initially thought but it doesn't work.
- AlexLachance
- Posts: 2226
- Joined: Thu Mar 11, 2021 8:14 am
- Location: Quebec
- x 2419
- x 2061
Re: PDM add-in task text box
If it's replicable, might wanna hit up your VAR. Maybe they could cook up a temporary solution for you.
Re: PDM add-in task text box
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?
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?
Re: PDM add-in task text box
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.
Re: PDM add-in task text box
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.
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.