C#WinForm中常用技术
来源:互联网 发布:安徽第一时间网络回放 编辑:程序博客网 时间:2024/06/16 15:27
Winform中的按钮要响应回车事件,是很简单的事情!只要在窗体中的属性设置一下就可以了!
比如有登录窗体(Form_Login),包含有两个按钮登录 (btnLogin)和退出(btnExit),
想要登录 (btnLogin)响应回车键,则设置窗体(Form_Login)的属性AcceptButton为btnLogin即可!
即Form_Login.AcceptButton=btnLogin; 同样道理,
设置窗体(Form_Login)的属性CancelButton为btnExit,就可以响应Esc键了!
即Form_Login.CancelButton=btnExit;
public class AppSettings
{
public static string AppConfig()
{
return System.IO.Path.Combine(Application.StartupPath, "App.config");//此处配置文件在程序目录下
}
public static string GetValue(string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
xDoc.Load(AppSettings.AppConfig());
XmlNode xNode;
XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings"); //补充,需要在你的app.config 文件中增加一下,<appSetting> </appSetting>
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
if (xElem != null)
return xElem.GetAttribute("value");
else
return "";
}
catch (Exception)
{
return "";
}
}
public static void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(AppSettings.AppConfig());
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
{
xElem1.SetAttribute("value", AppValue);
}
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(AppSettings.AppConfig());
}
}
private void btnSaveIP_Click(object sender, EventArgs e) { string strIP = txtIP.Text; if (!string.IsNullOrEmpty(strIP)) { AppSettings.SetValue("IPString",strIP); MessageBox.Show("IP配置成功!"); } }
public static string AppConfig() { return System.IO.Path.Combine(Application.StartupPath, "App.config");//此处配置文件在程序目录下 }
最后不要忘了将App.config文件拷贝到Bin/Debug目录下面
- C#WinForm中常用技术
- C#Winform技术,利用DataGridViewRow向DataGridView中添加数据
- winform中常用的控件
- winform中常用的控件
- 实际编程中常用的线程同步技术【C#,C++】
- C#-WinForm中WebBrowser应用
- C#winform中添加配置文件
- [C#] Winform 中打开超链接
- Winform TextBox中只能输入数字的几种常用方法(C#)
- Winform TextBox中只能输入数字的几种常用方法(C#)
- Winform TextBox中只能输入数字的几种常用方法(C#)
- [Winform]TextBox中只能输入数字的几种常用方法(C#)
- Winform TextBox中只能输入数字的几种常用方法(C#)
- Winform TextBox中只能输入数字的几种常用方法(C#)
- Winform TextBox中只能输入数字的几种常用方法(C#)
- [c#笔记]Winform TextBox中只能输入数字的几种常用方法(C#)
- 几个常用的WINFORM开发经验(C#)
- C#WinForm程序常用函数设计
- remove_if只支持一元谓词,害死我了
- 【数据库】mysql(1045 access denied for user 'root'@'localhost' using password yes)的解决方案
- ARM架构和X86架构对比
- XmLPullParser 笔记
- Jsp日历
- C#WinForm中常用技术
- 项目中嵌入微软Exchange邮箱代码
- 使用ibatis 通过多个参数来执行查询
- PDU短信的编码一般规则
- C/C++ 笔试面试(1)—— sizeof
- VCF文件解析
- eclipse的svn插件检出maven web项目时,无法被正确识别为正确的web工程
- 数据泵导入导出步骤
- USSD