?? form1.cs
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ReadingXML
{
/// <summary>
/// 讀取XML文件并將其內(nèi)容顯示在DataGrid組件中。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnReadXML;
private System.Windows.Forms.Button btnShowSchema;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的設(shè)計(jì)器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗體設(shè)計(jì)器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.panel1 = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnShowSchema = new System.Windows.Forms.Button();
this.btnReadXML = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Top;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(570, 23);
this.label1.TabIndex = 0;
this.label1.Text = "讀取XML文件中的數(shù)據(jù)";
this.label1.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 23);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(570, 403);
this.dataGrid1.TabIndex = 1;
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1,
this.btnShowSchema,
this.btnReadXML});
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 258);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(570, 168);
this.panel1.TabIndex = 5;
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(570, 120);
this.textBox1.TabIndex = 6;
this.textBox1.Text = "textBox1";
//
// btnShowSchema
//
this.btnShowSchema.Location = new System.Drawing.Point(160, 128);
this.btnShowSchema.Name = "btnShowSchema";
this.btnShowSchema.Size = new System.Drawing.Size(75, 32);
this.btnShowSchema.TabIndex = 5;
this.btnShowSchema.Text = "顯示架構(gòu)";
this.btnShowSchema.Click += new System.EventHandler(this.btnShowSchema_Click);
//
// btnReadXML
//
this.btnReadXML.Location = new System.Drawing.Point(24, 128);
this.btnReadXML.Name = "btnReadXML";
this.btnReadXML.Size = new System.Drawing.Size(88, 32);
this.btnReadXML.TabIndex = 4;
this.btnReadXML.Text = "讀取XML";
this.btnReadXML.Click += new System.EventHandler(this.btnReadXML_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(570, 426);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1,
this.dataGrid1,
this.label1});
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "讀取XML數(shù)據(jù)";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
// 申明一個(gè)數(shù)據(jù)集
DataSet dsAddress = new DataSet("address");
// 讀取XML文件,并將讀到的數(shù)據(jù)內(nèi)容顯示在DataGrid組件中。
private void btnReadXML_Click(object sender, System.EventArgs e)
{
string filePath = "address.xml";
dsAddress.ReadXml(filePath);
dataGrid1.DataSource = dsAddress;
dataGrid1.DataMember = "address";
dataGrid1.CaptionText = dataGrid1.DataMember;
}
// 顯示XML文件的框件結(jié)構(gòu)
private void btnShowSchema_Click(object sender, System.EventArgs e)
{
System.IO.StringWriter swXML = new System.IO.StringWriter();
dsAddress.WriteXmlSchema(swXML);
textBox1.Text = swXML.ToString();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -