⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pathnavigator.cs

📁 this is a good book for the visual c#
💻 CS
📖 第 1 页 / 共 2 页
字号:
// Fig. 18.9: PathNavigator.cs
// Demonstrates Class XPathNavigator.

using System;
using System.Windows.Forms;
using System.Xml.XPath; // Contains XPathNavigator 

public class PathNavigator : System.Windows.Forms.Form
{
   private System.Windows.Forms.Button firstChildButton;
   private System.Windows.Forms.Button parentButton;
   private System.Windows.Forms.Button nextButton;
   private System.Windows.Forms.Button previousButton;
   private System.Windows.Forms.Button selectButton;
   private System.Windows.Forms.TreeView pathTreeViewer;
   private System.Windows.Forms.ComboBox selectComboBox;
   private System.ComponentModel.Container components = null;
   private System.Windows.Forms.TextBox selectTreeViewer;
   private System.Windows.Forms.GroupBox navigateBox;
   private System.Windows.Forms.GroupBox locateBox;

   // navigator to traverse document
   private XPathNavigator xpath;

   // references  document for use by XPathNavigator
   private XPathDocument document;

   // references TreeNode list used by TreeView control
   private TreeNode tree;

   public PathNavigator()
   {
      InitializeComponent();

      // load in XML document
      document = new XPathDocument( "..\\..\\sports.xml" );
      
      // create navigator
      xpath = document.CreateNavigator();
      
      // create root node for TreeNodes
      tree = new TreeNode();

      tree.Text = xpath.NodeType.ToString(); // #root
      pathTreeViewer.Nodes.Add( tree );      // add tree

      // update TreeView control
      pathTreeViewer.ExpandAll();
      pathTreeViewer.Refresh();
      pathTreeViewer.SelectedNode = tree;    // hightlight root
   } // end constructor

      #region Windows Form Designer generated code
      
   protected override void Dispose( bool disposing )
   {
      if( disposing )
      {
         if (components != null) 
         {
            components.Dispose();
         }
      }
      base.Dispose( disposing );
   }

      
   /// <summary>
   /// Required method for Designer support - do not modify
   /// the contents of this method with the code editor.
   /// </summary>
   /// 
   private void InitializeComponent()
   {
      this.selectButton = new System.Windows.Forms.Button();
      this.nextButton = new System.Windows.Forms.Button();
      this.parentButton = new System.Windows.Forms.Button();
      this.firstChildButton = new System.Windows.Forms.Button();
      this.pathTreeViewer = new System.Windows.Forms.TreeView();
      this.previousButton = new System.Windows.Forms.Button();
      this.selectComboBox = new System.Windows.Forms.ComboBox();
      this.navigateBox = new System.Windows.Forms.GroupBox();
      this.locateBox = new System.Windows.Forms.GroupBox();
      this.selectTreeViewer = new System.Windows.Forms.TextBox();
      this.navigateBox.SuspendLayout();
      this.locateBox.SuspendLayout();
      this.SuspendLayout();
      // 
      // selectButton
      // 
      this.selectButton.Location = new System.Drawing.Point(8, 24);
      this.selectButton.Name = "selectButton";
      this.selectButton.Size = new System.Drawing.Size(80, 23);
      this.selectButton.TabIndex = 9;
      this.selectButton.Text = "Select";
      this.selectButton.Click += new System.EventHandler(this.selectButton_Click);
      // 
      // nextButton
      // 
      this.nextButton.Location = new System.Drawing.Point(48, 88);
      this.nextButton.Name = "nextButton";
      this.nextButton.Size = new System.Drawing.Size(80, 23);
      this.nextButton.TabIndex = 3;
      this.nextButton.Text = "Next";
      this.nextButton.Click += new System.EventHandler(this.nextButton_Click);
      // 
      // parentButton
      // 
      this.parentButton.Location = new System.Drawing.Point(8, 56);
      this.parentButton.Name = "parentButton";
      this.parentButton.Size = new System.Drawing.Size(80, 23);
      this.parentButton.TabIndex = 2;
      this.parentButton.Text = "Parent";
      this.parentButton.Click += new System.EventHandler(this.parentButton_Click);
      // 
      // firstChildButton
      // 
      this.firstChildButton.Location = new System.Drawing.Point(96, 56);
      this.firstChildButton.Name = "firstChildButton";
      this.firstChildButton.Size = new System.Drawing.Size(80, 24);
      this.firstChildButton.TabIndex = 1;
      this.firstChildButton.Text = "First Child";
      this.firstChildButton.Click += new System.EventHandler(this.firstChildButton_Click);
      // 
      // pathTreeViewer
      // 
      this.pathTreeViewer.FullRowSelect = true;
      this.pathTreeViewer.HideSelection = false;
      this.pathTreeViewer.ImageIndex = -1;
      this.pathTreeViewer.Location = new System.Drawing.Point(8, 264);
      this.pathTreeViewer.Name = "pathTreeViewer";
      this.pathTreeViewer.SelectedImageIndex = -1;
      this.pathTreeViewer.Size = new System.Drawing.Size(328, 144);
      this.pathTreeViewer.TabIndex = 13;
      // 
      // previousButton
      // 
      this.previousButton.Location = new System.Drawing.Point(48, 24);
      this.previousButton.Name = "previousButton";
      this.previousButton.Size = new System.Drawing.Size(80, 23);
      this.previousButton.TabIndex = 7;
      this.previousButton.Text = "Previous";
      this.previousButton.Click += new System.EventHandler(this.previousButton_Click);
      // 
      // selectComboBox
      // 
      this.selectComboBox.DropDownWidth = 240;
      this.selectComboBox.Items.AddRange(new object[] {
                                                         "/sports",
                                                         "/sports/game/name",
                                                         "/sports/game/paragraph",
                                                         "/sports/game[name=\'Cricket\']"});
      this.selectComboBox.Location = new System.Drawing.Point(96, 24);
      this.selectComboBox.Name = "selectComboBox";
      this.selectComboBox.Size = new System.Drawing.Size(240, 21);
      this.selectComboBox.TabIndex = 14;
      // 
      // navigateBox
      // 
      this.navigateBox.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                               this.firstChildButton,
                                                                               this.parentButton,
                                                                               this.previousButton,
                                                                               this.nextButton});
      this.navigateBox.Location = new System.Drawing.Point(80, 136);
      this.navigateBox.Name = "navigateBox";
      this.navigateBox.Size = new System.Drawing.Size(184, 120);
      this.navigateBox.TabIndex = 16;
      this.navigateBox.TabStop = false;
      this.navigateBox.Text = "Navigation Controls";
      // 
      // locateBox
      // 
      this.locateBox.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                             this.selectTreeViewer,
                                                                             this.selectComboBox,
                                                                             this.selectButton});
      this.locateBox.Location = new System.Drawing.Point(8, 8);
      this.locateBox.Name = "locateBox";
      this.locateBox.Size = new System.Drawing.Size(336, 128);
      this.locateBox.TabIndex = 17;
      this.locateBox.TabStop = false;
      this.locateBox.Text = "Locate Element";
      // 
      // selectTreeViewer
      // 
      this.selectTreeViewer.BackColor = System.Drawing.Color.Honeydew;
      this.selectTreeViewer.Location = new System.Drawing.Point(16, 56);
      this.selectTreeViewer.Multiline = true;
      this.selectTreeViewer.Name = "selectTreeViewer";
      this.selectTreeViewer.ReadOnly = true;
      this.selectTreeViewer.Size = new System.Drawing.Size(304, 64);
      this.selectTreeViewer.TabIndex = 15;
      this.selectTreeViewer.Text = "";
      // 
      // PathNavigator
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(352, 413);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                   this.locateBox,
                                                                   this.navigateBox,
                                                                   this.pathTreeViewer});
      this.Name = "PathNavigator";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -