disabling particular text in textbox control
-
Hi all, I have a textbox control in my windows form, where user can type the message and insert any picture he wants and export it. If he selects any picture, i am appending the message like "Picture picno Inserted" to the textbox. Now, my problem is, if he uses backspace key to delete anything in the message, the "Picture inserted" message should not get deleted. Means, that particular string has to be greyed out & disabled in the textbox. So, that i need not get bothered about calculating length for each keypress event. Could any one please tell me how can I achieve this? Meanwhile, i tried of selecting the text & changing the color of the selected text but didn't get how to disable that particular text... And also i tried of using RichTextBox too but in vain. Thanks in aDvance, Durga.
Strength is life, Weakness is death. --- Swami vivekananda
-
Hi all, I have a textbox control in my windows form, where user can type the message and insert any picture he wants and export it. If he selects any picture, i am appending the message like "Picture picno Inserted" to the textbox. Now, my problem is, if he uses backspace key to delete anything in the message, the "Picture inserted" message should not get deleted. Means, that particular string has to be greyed out & disabled in the textbox. So, that i need not get bothered about calculating length for each keypress event. Could any one please tell me how can I achieve this? Meanwhile, i tried of selecting the text & changing the color of the selected text but didn't get how to disable that particular text... And also i tried of using RichTextBox too but in vain. Thanks in aDvance, Durga.
Strength is life, Weakness is death. --- Swami vivekananda
You cannot disable part of the text in a textbox. You will have to handle TextChanged yourself.
Cheers, Vikram.
"I will put my new found knolage to good use" - Captain See Sharp. "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
-
Hi all, I have a textbox control in my windows form, where user can type the message and insert any picture he wants and export it. If he selects any picture, i am appending the message like "Picture picno Inserted" to the textbox. Now, my problem is, if he uses backspace key to delete anything in the message, the "Picture inserted" message should not get deleted. Means, that particular string has to be greyed out & disabled in the textbox. So, that i need not get bothered about calculating length for each keypress event. Could any one please tell me how can I achieve this? Meanwhile, i tried of selecting the text & changing the color of the selected text but didn't get how to disable that particular text... And also i tried of using RichTextBox too but in vain. Thanks in aDvance, Durga.
Strength is life, Weakness is death. --- Swami vivekananda
Create your own class similar to...
public class picno
{
private int _PictureNumber;public int PictureNumber { get { return \_PictureNumber; } set { \_PictureNumber = value; } } public override string ToString() { return "Picture " + \_PictureNumber.ToString() + " Inserted"; } public picno(int PictureNumber) { \_PictureNumber = PictureNumber; } }
then, when a picture is selected, create an instance of this assigning the picture number to the property and update the text. Something like...
picno myPicNo = new picno(25);
textBox1.Tag = myPicNo;
textBox1.Text += textBox1.Text + " " + (picno)textBox1.Tag;On the text changed event, look to see if the alteration would change any text that matches (picno)textBox1.Tag and disallow if needed. (You may need to use (picno)textBox1.Tag.ToString() for some operations)
modified on Wednesday, February 06, 2008 6:41:19 AM