I have the below code that allows a user to write in a executable (i.e. notepad.exe) and then clicking the start button it will start the process.
However, how do I make the TextBox accept enter/return key? I put in AcceptsReturn=true but it is not doing anything. I have also set in Visual Studio the property Accept Return = True – still nothing.
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace process_list
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
Process process = new Process();
process.StartInfo.FileName = text;
process.Start();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.AcceptsReturn = true;
}
}
}
Set the
AcceptButtonof the form to your button. You don’t needAcceptsReturnthen, because Enter automatically triggers the button.