C#常用开发技巧
来源:互联网 发布:女生可怕经历知乎 编辑:程序博客网 时间:2024/05/17 03:22
1、字符串简单加解密(常用于配置文件)
static public string Encode(string str)
{
string htext = "";
for (int i = 0; i < str.Length; i++)
{
htext = htext + (char)(str[i] + 10 - 1 * 2);
}
return htext;
}
static public string Decode(string str)
{
string dtext = "";
for (int i = 0; i < str.Length; i++)
{
dtext = dtext + (char)(str[i] - 10 + 1 * 2);
}
return dtext;
}
2、From加载时,默认光标。
方法<1>、在Load()事件或者构造函数中加入:this.ActiveControl = control;
方法<2>、将control的TabIndex设置为0;
3、密码文本框
txt_password.PasswordChar = '*'; //***
txt_password.UseSystemPasswordChar = true;//小圆点
4、设置窗体为屏幕居中显示
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(SystemInformation.WorkingArea.Width / 2 - this.Width / 2, SystemInformation.WorkingArea.Height / 2 - this.Height / 2);
5、修改配置文件
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");
node = doc.SelectSingleNode(@"//add[@key='user']");
ele = (XmlElement)node;
ele.SetAttribute("value", this.user.Text);
node = doc.SelectSingleNode(@"//add[@key='password']");
ele = (XmlElement)node;
ele.SetAttribute("value", this.password.Text);
try
{
doc.Save(Application.ExecutablePath + ".config");
MessageBox.Show("保存成功.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
6、窗体大小改变(展开和收起)
if (button.Text == "展开>>")
{
this.Height += 180;
button.Text = "收起<<";
}
else
{
this.Height -= 180;
button.Text = "展开>>";
}
7、登录界面关闭,进入主界面
在main()中加入:
using (Login login = new Login())
{
if (login.ShowDialog() == DialogResult.OK)
{
Application.Run(new MainForm());
}
}
8、Process
System.Diagnostics.Process.Start("osk.exe");//打开屏幕小键盘
System.Diagnostics.Process.Start("www.baidu.com");//打开网址
- C#常用开发技巧
- C# 开发和使用中的23个技巧(常用)
- C# 开发和使用中的23个技巧(常用)
- C# 开发和使用中的23个技巧(常用)
- C#常用技巧
- C#常用技巧
- c#常用的技巧
- C#常用小技巧
- VC常用开发技巧
- Asp开发常用技巧
- 常用开发技巧
- VS开发常用技巧
- android开发 常用技巧
- php开发常用技巧
- Web开发常用技巧
- iOS开发常用技巧
- swift开发常用技巧
- Mac开发常用技巧
- Python 基础语法(一)
- MIME的常见类型
- 软考-计算机基础知识
- Jquery MVC 解决跨域问题
- AutoHotKey的那些事儿:(二)、AutoHotkey变量、函数、数组、类的使用
- C#常用开发技巧
- mysql时间
- int main(int argc, char* argv[])
- 如何阻止QQ右下角弹出新闻框
- 20151015笔试小结
- 转自“展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告”
- C/C++内存管理详解 堆 栈
- java 读取文件 乱码
- html及Dreamweaver学习心得