在文本框中,保护第一个单词,但允许在这些单词之后添加/编辑文本 [英] In a textbox, protect the first words, but allow adding/editing to text past those words

查看:50
本文介绍了在文本框中,保护第一个单词,但允许在这些单词之后添加/编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个C#文本框(使用.NET表单),我将在其中接受用户字符串进行某些输入.

So I have a textbox in C# (Using .NET forms) where I am going to accept a users string for some input.

此字符串的开头已经有文本(自变量),无论如何,该文本都会存在于字符串的开头.它必须在那里.我希望他们意识到这一点,但不能从文本框中删除这些单词(因此,无论如何,他们都不会认为已经删除了该单词)

This string already has text (arguments) at the beginning that will exist at the beginning of the string no matter what. It must be there. I want them to be aware of this, but not be able to delete the words from the textbox (so they wont think theyve deleted it already when its going to be there anyways)

因此,这些第一个参数不能删除或编辑.

So these first arguments must not be able to be deleted or edited.

这些参数之后的任何文本都可以照常自由添加或修改.

Any text after these arguments can be added or modified freely as normal.

这在C#中可行吗?

推荐答案

假设使用WinForms,则可以改用RichTextBox控件.设置 Multiline = False 属性,下面是锁定前几个字符的示例:

Assuming WinForms, you can use a RichTextBox control instead. Set the Multiline=False property and here is an example to lock the first characters:

richTextBox1.Text = "LOCKED";
richTextBox1.SelectAll();
richTextBox1.SelectionProtected = true;

或此操作,它将仅锁定前六个字符"LOCKED",但允许用户更改句子的其余部分:

or this, which will only lock the first six characters "LOCKED", but allow the user to change the rest of the sentence:

richTextBox1.Text = "LOCKED information";
richTextBox1.Select(0, 6);
richTextBox1.SelectionProtected = true;

这篇关于在文本框中,保护第一个单词,但允许在这些单词之后添加/编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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