<一>路径主要分为绝对路径和相对路径
1.绝对路径
主要注意C#中“\”是特殊字符,所以写绝对路径时候要改为“\”
或者为了简化写法直接在路径前加上@
string filePath=@”C:\Users\18333\Desktop\aaa.txt”;
string filePath=””C:\Users\18333\Desktop\aaa.txt””;
2.相对路径
可以用
string filePath=Application.StartupPath+”\filename.txt”;
找到应用程序的可执行文件的路径
以后可以保证拥有这个程序的硬件可以找到此文件。
这个文件置于bin的Debug下
<二>所有控件TextChanged触发事件
1/我首先是把窗体中某一类型的控件都集合在自己定义的List,窗体一构造就执行
即在窗体的构造函数里写
public Form()
{
GetAllCertainControls(this,”NumericUpDown”,NumericControls);//注意初始化需要
GetAllCertainControls(this, “CheckBox”,CheckBoxControls);//注意初始化需要
}
//新方法遍历所有NumericUpDown控件
public static List
public static List
//将特定类型的控件集合到定义好的List中
private void GetAllCertainControls(Control control, string TypeName, List
{
string cTypeName = null;
for (int i = 0; i < control.Controls.Count; i++)
{
cTypeName = control.Controls[i].GetType().Name;
if (control.Controls[i].HasChildren && !(cTypeName == TypeName))
{
GetAllCertainControls(control.Controls[i], TypeName, list);
}
else if (cTypeName == TypeName)
{
list.Add(control.Controls[i]);
}
}
}
2.网上的一种方法是:
先定义一个全局变量
在想要得知的控件的TextChanged的事件里+1
/??还想知道有没有其他办法