我有一个问题,我如何才能将长代码放入具有“发送者”和“KeyPressEventArgs”的空域中,然后在许多其他空域中使用该空域。例如:
private void Value_KeyPress(object sender, KeyPressEventArgs e)
{
//I want my void shortcut here
CheckValue(???);
}
这是我的空白,我想要我的代码从哪里来
private virtual void CheckValue(object sender, KeyPressEventArgs e)
{
var comboBox = (ComboBox)sender;
comboBox.DroppedDown = true;
var stringToFind = "";
if (e.KeyChar == (char)8)
{
if (comboBox.SelectionStart <= 1)
{
comboBox.Text = "";
return;
}
if (comboBox.SelectionLength == 0)
stringToFind = comboBox.Text.Substring(0, comboBox.Text.Length - 1);
else
stringToFind = comboBox.Text.Substring(0, comboBox.SelectionStart - 1);
}
else
{
if (comboBox.SelectionLength == 0)
stringToFind = comboBox.Text + e.KeyChar;
else
stringToFind = comboBox.Text.Substring(0, comboBox.SelectionStart) + e.KeyChar;
}
var indexOfFoundString = -1;
// Search the string in the ComboBox list.
indexOfFoundString = comboBox.FindString(stringToFind);
if (indexOfFoundString != -1)
{
comboBox.SelectedText = "";
comboBox.SelectedIndex = indexOfFoundString;
comboBox.SelectionStart = findString.Length;
comboBox.SelectionLength = comboBox.Text.Length;
e.Handled = true;
}
else
e.Handled = true;
我真的希望,你理解我的问题,可以给我答案:)