如何让 winforms 文本框中的文本以不可更改的文本为前缀? [英] How do I have text in a winforms textbox be prefixed with unchangable text?

查看:27
本文介绍了如何让 winforms 文本框中的文本以不可更改的文本为前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许创建和运行自动化测试脚本的应用程序.测试脚本本身是可移植的 xml 文件,这意味着一旦配置好它就可以在任何计算机上运行.

I have an application that allows the creation and running of automated testing scripts. The test scripts themselves are xml files that are meant to be portable, which means that once one is configured it should work on any computer.

保存在 xml 文件中的配置设置之一是要复制的构建的位置.根据计算机根文件夹的设置可能会有所不同,例如在我的计算机上,我可能正在查看 F:\Builds\2-QA\ClientA 而作为另一台机器,它需要 \\server1\Public\Builds\2-QA\ClientA,如果服务器发生变化,它将是 `\newserver\Public\Builds\2-QA\ClientA'.

One of the configuration settings saved in the xml files is the location of builds to copy over. Depending on the setup of the computer root folder can be different, for example on my computer I may be looking at F:\Builds\2-QA\ClientA where as another machine it requires \\server1\Public\Builds\2-QA\ClientA, and if the server changes it would be `\newserver\Public\Builds\2-QA\ClientA'.

我仅通过让用户将最后一部分(例如 2-QA\ClientA)保存在 xml 中来解决此问题,并且根由 App.Config 中的应用程序设置解决.

I solve this descrepency by only having the user save the last part (e.g. 2-QA\ClientA) in the xml, and the root is resolved by an application setting in App.Config.

这样做的问题在于,在用户进入应用程序源目录的 GUI 中,不清楚他们必须输入文件夹结构的哪一部分以及 App.Config 解决了什么问题.

The problem with this is that in the GUI where the user enters the application source directory, it's not clear what part of the folder structure they have to enter and what is resolved by App.Config.

因此,我希望我的文本框在内部自动填充根目录,但以只读方式.例如,文本框将显示F:\Builds\,用户可以在最后添加他们想要的文件夹结构,但不能删除F:\Builds\.保存时,我打算去掉 F:\Builds\ 部分,但如果他们能够(有意或无意)从 F:\Builds 中删除字符,则不能依赖该部分\.

Therefore, what I would like is my textbox to have the root directory auto-populated inside, but in a read-only way. So for instance, the textbox will display F:\Builds\ and the user can add the folder structure they want at the end, but they cannot delete any part of the F:\Builds\. When saving I intend to strip off the F:\Builds\ part, but that can't be relied upon if they are able to (intentionally or not) delete characters from F:\Builds\.

有什么关于实现这一点的建议吗?

Any suggestions on accomplishing this?

推荐答案

尝试使用 MaskedTextBox 并设置其 掩码属性 到你想要前缀的字符串.

Try using a MaskedTextBox and set its Mask property to the string you want prefixed.

类似:F:\Builds\LLLLLLLLLLLL

Something like: F:\Builds\LLLLLLLLLLLL

这篇关于如何让 winforms 文本框中的文本以不可更改的文本为前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆