2、C#入门第2课

it2022-05-09  16

1、XML文件读取

XmlDocument xml; string path = "F:\\C#\\功2016.xml"; if (System.IO.File.Exists(path)) { xml = new XmlDocument(); xml.Load(path); //加载XML文档 } else { xml = new XmlDocument(); //创建根节点 config xml.AppendChild(xml.CreateXmlDeclaration("1.0", "utf-8", "")); XmlElement one = xml.CreateElement("功能测试参数"); //把根节点加到xml文档中 xml.AppendChild(one);

XmlElement two = xml.CreateElement(textBox1.Text); one.AppendChild(two); XmlElement three = xml.CreateElement("测试项目");

two.AppendChild(three);

xml.Save(path);

}

 

2、添加类

单击项目名,添加类是最简单的方法,并注意将类的访问范围改为public ,这样你的代码就可以访问这个类了3、关闭窗体关闭窗体 this.Close(); 关闭程序 Application.Exit();4、c# 程序运行时窗口在屏幕中间

Form(窗体)有一个属性

>StartPosition(确定窗体第一次出现的位置)

可选:

>>Manual:与Location属性一起用的,控制窗体的位置,通过在Location属性中输入数值去定位。

>>CenterScreen:使窗体在当前屏幕上居中

>>WindowsDefaultLocation:windows默认位置上。

>>WindowsDefaultBounds:windows默认位置上,大小由Windows决定。

>>CenterParent:使窗体在父窗体的边界内居中

转载于:https://www.cnblogs.com/MiLu/p/5609359.html

相关资源:C#入门经典(第3版)

最新回复(0)