Disable

aewarnick

Senior Contributor
Joined
Jan 29, 2003
Messages
1,031
Is there any way to disable (Read Only) only part of a richTextBox? I want text boxes that can be read and added to but not edited.
 
Last edited:
You want to be able to add to it but not edit it? If you set the
ReadOnly property to True then it will make it so that you can't modify
it.

If you mean you want to be able to edit only part of the RTB, then
no this can't be done without using some slimy hack. You could try
parsing out all of the text in the desired "editable" portions of the
RTB and reinserting it after the RTB has been reset to it's original
text. This would cause the text in the RTB you don't want to edit to
revert itself back everytime you tried to change it, but would retain
the text that you entered into the desired editable area.

That probably didn't make too much sense, but it's hard to explain.
If it is indeed what you're looking for, I'll try to whip up an example.
 
I do not think that is what I want. Try my program out and you should see what I want to do. I want to get rid of the extra form that I have pop up so that the text can be appended and just append the text right from the first form but be secure about it in that someone else cannot go and edit what was already written.

[edit]removed binaries - divil[/edit]
 

Attachments

Last edited by a moderator:
I just read my last post and realized why noone got back to me. It does not make any sense. I will try to explain it better.

Right now, I have 2 forms. The first form is the main form and has all the readonly tb's whereas the second form is created with the clidk of a button and it has the empty editable forms. When the user types in the additional info it creates a text file (when save pressed) if none exists and appends it if it does. That form is disposed and the readonly form reads the whole text file, displaying the old (if there is any) and new info.

I am wondering if there is a way that the user could add to the info in the readonly boxes but not change what is already displayed while writing in that same box.
VolteFace, maybe what you suggested would be fine? Is there a good example you can whip up?
 
The .NET RichTextBox control supports portions of the text being read-only. Here's an example to show this:

Visual Basic:
RichTextBox1.Text = "The quick brown horse jumps over the lazy fox."
RichTextBox1.Text &= Environment.NewLine
RichTextBox1.Text &= "This line will be editable, the first will not."
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = RichTextBox1.Text.IndexOf(ControlChars.Lf)
RichTextBox1.SelectionProtected = True
RichTextBox1.SelectionStart = RichTextBox1.Text.Length + 1

C#:
richTextBox1.Text = "The quick brown horse jumps over the lazy fox.";
richTextBox1.Text += Environment.NewLine;
richTextBox1.Text += "This line will be editable, the first will not.";
richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = richTextBox1.Text.IndexOf("\n");
richTextBox1.SelectionProtected = true;
richTextBox1.SelectionStart = richTextBox1.Text.Length + 1;
 
That is exactly!!!! what I was looking for!!!!!! Thank you so much for taking the time to help me.
 
Back
Top