سلام دوباره! دیدم حال نوشتن دارم یدونه آماده کردم:
SmartTextBox.png
public class SmartTextBox : TextBox
{
public SmartTextBox()
{
this.TextChanged += SmartTextBox_TextChanged;
this.KeyPress += SmartTextBox_KeyPress;
}
bool Removed = false;
bool Editing = false;
void SmartTextBox_TextChanged(object sender, EventArgs e)
{
if (Editing || Removed)
return;
Editing = true;
int selctStart = this.SelectionStart;
int lastSpacePos = findLastSpacePosition();
string word = this.Text.Substring(lastSpacePos, selctStart - lastSpacePos);
if (word.Length > 0)
foreach (var src in this.AutoCompleteCustomSource)
{
string s = src.ToString();
if (s.StartsWith(word))
{
this.Text = this.Text.Insert(selctStart, s.Substring(word.Length));
this.Select(selctStart, s.Length - word.Length);
break;
}
}
Editing = false;
}
int findLastSpacePosition()
{
for (int i = this.SelectionStart - 1; i >= 0; i--)
if (this.Text[i] == ' ')
return i + 1;
return 0;
}
void SmartTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == ' ')
{
this.Select(this.SelectionStart + this.SelectionLength, 0);
e.Handled = false;
}
Removed = (e.KeyChar == '\b');
}
}
پروژه هم اگه نیاز شد: