Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace multiline_text_suggest
- {
- public partial class Form1 : Form
- {
- ListBox listBox = new ListBox();
- public Form1()
- {
- InitializeComponent();
- Controls.Add(listBox);
- listBox.Hide();
- textsplit();
- }
- string intellisenes;
- private void textsplit() {
- listBox1.Items.Clear();
- foreach (string c in textBox.Text.Split()) {
- listBox1.Items.Add(c);
- }
- intellisenes = listBox1.Items[listBox1.Items.Count-1].ToString().Trim();
- }
- void listBox_SelectedIndexChanged(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == (decimal)Keys.Enter)
- {
- textBox.Text += ((ListBox)sender).SelectedItem.ToString();
- textBox.Focus();
- listBox.Hide();
- }
- }
- private void textBox1_KeyUp(object sender, KeyEventArgs e)
- {
- textsplit();
- listBox.SetBounds(textBox.Left, textBox.Top + textBox.Height, textBox.Width + 20, 40);
- listBox.KeyDown += listBox_SelectedIndexChanged;
- List<string> list = new List<string>(){"king","kong"};
- var localList = list.Where(z => z.StartsWith(intellisenes.Trim())).ToList();
- if (localList.Any() && !string.IsNullOrEmpty(textBox.Text) && !string.IsNullOrWhiteSpace(textBox.Text))
- {
- listBox.DataSource = localList;
- listBox.Show();
- listBox.Focus();
- }
- }
- private void textBox_TextChanged(object sender, EventArgs e)
- {
- textsplit();
- }
- }
- }
Add Comment
Please, Sign In to add comment