How is the text in a winforms textbox prefixed with unchangeable text?

I have an application that allows you to create and run automated test scripts. The test scripts themselves are xml files designed for portability, which means that once configured it should work on any computer.

One of the configuration settings stored in the xml files is the location of the copies to be copied. Depending on the settings, the root folder of the computer may be different, for example, on my computer, I can look at F:\Builds\2-QA\ClientA

where as another computer it needs \\server1\Public\Builds\2-QA\ClientA

, and if the server changes, it will be `\ newserver \ Public \ Builds \ 2-QA \ ClientΓ’ ".

I only solve this descrepency if the user saves the last part (for example 2-QA\ClientA

) in the xml and the root is resolved with the app in the App.Config.

The problem is that in the GUI where the user goes to the source directory of the application, he doesn't understand which part of the folder structure they have to enter and what the App.Config is allowed.

Therefore, I would like my textbox to have a root directory auto-populated inside, but read-only. So, for example, a textbox will display F:\Builds\

and the user can add the folder structure they want at the end, but they cannot delete any part F:\Builds\

. When saving, I intend to disable the part F:\Builds\

, but it cannot be relied on if they can (intentionally or not) remove characters from F:\Builds\

.

Any suggestions on how to accomplish this?

0


source to share


3 answers


Try using MaskedTextBox and set the mask property to the string you want to prefix.



Something like: F: \ Builds \ LLLLLLLLLLLL

+2


source


My thought:

Forget about making it unmodified.



Have a function that works when the text changes. If the prefix is ​​N characters long, change the first N characters of the text box to a prefix.

0


source


Could you please add a shortcut in front of the textbox. The label will contain text that you do not want to change, allowing the user to understand that you want the next bit to be entered in the text box.

0


source







All Articles