C#让winform程序中的输入文本框保留上次的输入
选中TextBox控件,在属性窗格中找到(ApplicationSettings),然后设置它。
绑定配置文件
private Settings settings = new Settings();
private void MainForm_Load(object sender, EventArgs e)
{
this.txtTargetInitialCatalog.Text = settings.sadbname;
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
settings.sadbname = this.txtTargetInitialCatalog.Text;
settings.Save();
}
C# TextBox控件,回车键实现点击按钮即自动登录
摘要
1)TextBox的KeyUp事件,即在按下键盘后,抬起的时候触发的事件跳转
2)判断e.KeyCode是否为回车键
3)使用buttern1_Click(sender,e)实现按钮的点击
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Control || e.KeyCode == Keys.Enter)
{
button1.Focus();
button1_Click(sender, e);
}
}
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。