fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void Form1_Load(object sender, EventArgs e)
  20. {
  21. toolStripTextBox1.Text = "https://w...content-available-to-author-only...o.jp/";
  22. webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
  23. webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
  24. //webBrowser1.NewWindow += new CancelEventHandler(webBrowser1_NewWindow);
  25. //treeView1.NodeMouseClick += new TreeNodeMouseClickEventHandler(treeView1_NodeMouseClick);
  26. treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
  27. }
  28.  
  29. void webBrowser1_NewWindow(object sender, CancelEventArgs e)
  30. {
  31. e.Cancel = true;
  32. }
  33.  
  34. int objcount = 0;
  35. HtmlElement oldelem;
  36. string oldstring;
  37.  
  38. private void toolStripButton1_Click(object sender, EventArgs e)
  39. {
  40. try
  41. {
  42. objcount = 0;
  43. this.Enabled = false;
  44. webBrowser1.SuspendLayout();
  45. webBrowser1.Navigate(toolStripTextBox1.Text);
  46. }
  47. catch
  48. {
  49. statusStrip1.Text = "URLが不正です。" +
  50. toolStripTextBox1.Text;
  51. this.Enabled = true;
  52. }
  53. }
  54.  
  55. void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  56. {
  57. objcount++;
  58. }
  59.  
  60. void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  61. {
  62. objcount--;
  63. if (objcount == 0)
  64. {
  65. treeView1.SuspendLayout();
  66. treeView1.Nodes.Clear();
  67. TreeNode tnBody = new TreeNode();
  68. tnBody.Text = "Body";
  69. tnBody.Tag = webBrowser1.Document.Body;
  70. this.NodeSet(tnBody, webBrowser1.Document.Body);
  71. treeView1.Nodes.Add(tnBody);
  72. //treeView1.ExpandAll();
  73. this.Enabled = true;
  74. //webBrowser1.ScrollBarsEnabled = false;
  75. treeView1.ResumeLayout();
  76. webBrowser1.ResumeLayout();
  77. }
  78. }
  79. //htmlDocument再帰的に調べてノードを作成
  80. void NodeSet(TreeNode tn, HtmlElement elem)
  81. {
  82. foreach (HtmlElement e in elem.Children)
  83. {
  84. TreeNode t = new TreeNode();
  85. t.Text = e.TagName;
  86. t.Tag = e;
  87. tn.Nodes.Add(t);
  88. this.NodeSet(t, e);
  89. }
  90. }
  91. void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  92. {
  93. //e.Node.Expand();
  94. this.DataSet(e.Node);
  95. }
  96.  
  97. void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  98. {
  99. this.DataSet(e.Node);
  100. }
  101. void DataSet(TreeNode node)
  102. {
  103. if (oldelem != null) oldelem.Style = oldstring;
  104. textBox1.Clear();
  105. if (node.Tag == null) return;
  106. HtmlElement elem = (HtmlElement)node.Tag;
  107. //this.TextSet("InnerHtml:" + elem.InnerHtml);
  108. //this.TextSet("InnerText:" + elem.InnerText);
  109. //this.TextSet("OuterHtml:" + elem.OuterHtml);
  110. //this.TextSet("OuterText:" + elem.OuterText);
  111. textBoxInnerHtml.Text = elem.InnerHtml;
  112. textBoxInnerText.Text = elem.InnerText;
  113. textBoxOuterHtml.Text = elem.OuterHtml;
  114. textBoxOuterText.Text = elem.OuterText;
  115. this.TextSet("[Id ]:" + elem.Id);
  116. if (elem.Name != string.Empty && elem.Name.Length != 0)
  117. this.TextSet("[Name ]:" + elem.Name);
  118. this.TextSet("[Style ]:" + elem.Style);
  119. this.TextSet("[TagName ]:" + elem.TagName);
  120. this.TextSet("[ClientRectangle]:" + elem.ClientRectangle.ToString());
  121. this.TextSet("[OffsetRectangle]:" + elem.OffsetRectangle.ToString());
  122. this.TextSet("[ScrollRectangle]:" + elem.ScrollRectangle.ToString());
  123. this.TextSet("[Children ]:" + elem.Children.Count.ToString());
  124. webBrowser1.Document.Window.ScrollTo(elem.OffsetRectangle.X, elem.OffsetRectangle.Y);
  125. //HtmlElementのborder機能を使って枠線を実現してるので
  126. //HtmlElementを切り替えた場合に元のStyleに戻すために
  127. oldstring = elem.Style;
  128. oldelem = elem;
  129. elem.Style += "border:solid";
  130. }
  131. void TextSet(string s)
  132. {
  133. textBox1.AppendText(s + Environment.NewLine);
  134. }
  135. }
  136. }
  137.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty