Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. disabling particular text in textbox control

disabling particular text in textbox control

Scheduled Pinned Locked Moved C#
questionhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DKalepu
    wrote on last edited by
    #1

    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

    V D 2 Replies Last reply
    0
    • D DKalepu

      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

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D DKalepu

        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

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups