简体   繁体   中英

How to turn textbox contents into link

I want to turn several words in textbox contents into a clickable links to another forms, if the word is recognized. Is that possible?

Could you check the value of the textbox each time it changes to see if it is a recognized word? If its a recognized word, you could style the text (make it blue and underlined) and set a boolean variable ( clickable ) to true. Then in a Click event, check to see if clickable is true, and if it is handle the event.

 boolean textbox1Clickable = false;

 public void textbox1_TextChanged(object sender, EventArgs e)
 {
      string s = textbox1.Text;
      if(TextIsARecognizedWord(s))
      {
          //set the fore color of textbox1 to blue
          //set the font style of textbox1 to underlined
          textbox1Clickable = true;
      }
      else
      {
          //set the fore color of textbox1 to black
          //set the font style of textbox1 to normal (not underlined)
          textbox1Clickable = false;
      }
 }

 public void textbox1_Click(object sender, System.EventArgs e)
 {
      if(textbox1Clickable)
      {
           //open your other form based on what is in textbox1.Text
      }
 }

Or do you want the textbox to actually turn into a link that cannot be typed into?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM