Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace multiline_text_suggest
  11. {
  12. public partial class Form1 : Form
  13. {
  14. ListBox listBox = new ListBox();
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. Controls.Add(listBox);
  19. listBox.Hide();
  20. textsplit();
  21. }
  22. string intellisenes;
  23. private void textsplit() {
  24. listBox1.Items.Clear();
  25. foreach (string c in textBox.Text.Split()) {
  26. listBox1.Items.Add(c);
  27. }
  28.  
  29. intellisenes = listBox1.Items[listBox1.Items.Count-1].ToString().Trim();
  30. }
  31.  
  32. void listBox_SelectedIndexChanged(object sender, KeyEventArgs e)
  33. {
  34. if (e.KeyValue == (decimal)Keys.Enter)
  35. {
  36. textBox.Text += ((ListBox)sender).SelectedItem.ToString();
  37. textBox.Focus();
  38. listBox.Hide();
  39.  
  40. }
  41. }
  42.  
  43. private void textBox1_KeyUp(object sender, KeyEventArgs e)
  44. {
  45. textsplit();
  46. listBox.SetBounds(textBox.Left, textBox.Top + textBox.Height, textBox.Width + 20, 40);
  47. listBox.KeyDown += listBox_SelectedIndexChanged;
  48. List<string> list = new List<string>(){"king","kong"};
  49. var localList = list.Where(z => z.StartsWith(intellisenes.Trim())).ToList();
  50. if (localList.Any() && !string.IsNullOrEmpty(textBox.Text) && !string.IsNullOrWhiteSpace(textBox.Text))
  51. {
  52. listBox.DataSource = localList;
  53. listBox.Show();
  54. listBox.Focus();
  55. }
  56.  
  57. }
  58.  
  59. private void textBox_TextChanged(object sender, EventArgs e)
  60. {
  61. textsplit();
  62. }
  63. }
  64. }
Add Comment
Please, Sign In to add comment