「sender」と「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;
あなたが私の問題を理解し、私に答えてくれることを本当に願っています:)