Click here to Skip to main content
15,885,107 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

how can I make a Textbox deletable by the User at runtime, without
using the design mode?
The User should be able to select the Textbox and remove it with the "DELETE" Key.
I use the C# VSTO Word Add-in in Visual Studio.
I would be happy for any response!

What I have tried:

I searched in the Web, but cannot find anything usefull.
I just started with programming, so don't hate me for this noob question.
Posted
Updated 19-Oct-19 22:25pm

1 solution

See the section "To add and remove controls on the active document" here: Add controls to document at run time in VSTO Add-in - Visual Studio | Microsoft Docs[^]

Detecting the Delete key from the KeyPress event will not work, but you can use KeyDown instead. Here is an example: Keypress Event in C#[^]
Deleting the TextBox in the event is not a good idea, but maybe you can set the .Visible property to false.
 
Share this answer
 
v2
Comments
Member 14625136 20-Oct-19 7:20am    
Thank you for the answer!
But I don't want a Button (or something else) to remove the TextBox, the User should be able to select the TextBox and delete it with the "Del" key.
So the Textbox should behave the same like a original Word TextBox.
Dave Kreskowiak 20-Oct-19 13:05pm    
How are you going to do this without a design mode?

Click in the TextBox will set the focus to the TextBox and place the caret. Hitting the DEL key will delete the character where the caret is at, not delete the TextBox.

Without a design mode to change the mode of interation with the TextBox, there's no way to tell the difference between using the TextBox and designing it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900