As previously stated; you could either compound the IF statements into one or nest them
if (e.Control) && e.KeyCode == Keys.D2 && textbox1.Text == "test" ) {
textBox1.Text="2";
}
if (e.Control) && e.KeyCode == Keys.D2) {
if (textbox1.Text == "test" ) {
textBox1.Text="2";
}
}
Now one thing about the nested version is this could be further expanded if you had to add in various renditions of the third condition
if (e.Control) && e.KeyCode == Keys.D2) {
if (textbox1.Text == "test" ) { textBox1.Text="2"; }
if (textbox1.Text == "exam" ) { textBox1.Text="3"; }
}
Or if there would be a bunch of
textbox1.Text values to check, you could utilize a
switch...case
block
if (e.Control) && e.KeyCode == Keys.D2) {
switch(textbox1.Text) {
case "test":
textBox1.Text="2";
break;
case "exam":
textBox1.Text="3";
break;
case "quiz":
case "check":
textBox1.Text = "4";
break;
default:
textBox1.text = "0"
break;
}
}
Reference:
C# switch statement | Microsoft Docs[
^]
Please note that all of these comparisons are case-sensitive by default