Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. private void TextBox1_TextChanged(object sender, EventArgs e)
  2. {
  3. int first = this.textBox1.TextLength;
  4. string padrao = "asdfjdkjdfColocar esse texto no TextBoxqewprqewriworuoewi";
  5. string textIndex = padrao.Remove(0, padrao.IndexOf(this.textBox1.Text, 0) + this.textBox1.TextLength);
  6. this.textBox1.Text = this.textBox1.Text.Insert(this.textBox1.Text.Length, textIndex);
  7. this.textBox1.Select(first, this.textBox1.Text.Length);
  8. }
  9.  
  10. public Form1()
  11. {
  12. InitializeComponent();
  13.  
  14. this.textBox1.AutoCompleteMode = AutoCompleteMode.Append;
  15. this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
  16.  
  17. AutoCompleteStringCollection stringCollection = new AutoCompleteStringCollection
  18. {
  19. "asdfjdkjdfColocar esse texto no TextBoxqewprqewriworuoewi"
  20. };
  21.  
  22. textBox1.AutoCompleteCustomSource = stringCollection;
  23. }
  24.  
  25. string typed = "";
  26.  
  27. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  28. {
  29. string padrao = "asdfjdkjdfColocar esse texto no TextBoxqewprqewriworuoewi";
  30.  
  31. e.Handled = true;
  32.  
  33. // TODO:: tratamento de delete, backspace, escape etc
  34.  
  35. typed += ((char)e.KeyChar).ToString();
  36.  
  37. this.textBox1.Text = typed;
  38.  
  39. int indexOf = padrao.IndexOf(typed, StringComparison.OrdinalIgnoreCase);
  40. if (indexOf >= 0)
  41. {
  42. this.textBox1.Text += padrao.Substring(indexOf + typed.Length);
  43. }
  44.  
  45. this.textBox1.SelectionStart = typed.Length;
  46. this.textBox1.SelectionLength = this.textBox1.Text.Length - typed.Length;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement