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. using System.Threading;
  10. using System.Drawing.Drawing2D;
  11. using System.Drawing.Imaging;
  12.  
  13. namespace WindowsFormsApplication1
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. this.Load += new EventHandler(Form1_Load);
  21. this.Shown += new EventHandler(Form1_Shown);
  22. }
  23.  
  24. WebBrowser webBrowser1 = new WebBrowser();
  25. int Count = 0;
  26. const int ClientWidth = 1024;
  27. const int ClientHeight = 512;
  28. void Form1_Load(object sender, EventArgs e)
  29. {
  30. webBrowser1.Dock = DockStyle.Fill;
  31. webBrowser1.ScrollBarsEnabled = false;
  32. this.ClientSize = new Size(ClientWidth, ClientHeight);
  33. this.Controls.Add(webBrowser1);
  34. webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
  35. webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
  36. }
  37.  
  38. void Form1_Shown(object sender, EventArgs e)
  39. {
  40. webBrowser1.Navigate("http://a...content-available-to-author-only...h.net/test/read.cgi/software/1335443552/");
  41. }
  42.  
  43. void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  44. {
  45. Interlocked.Increment(ref Count);
  46. }
  47.  
  48. void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  49. {
  50. Interlocked.Decrement(ref Count);
  51. if (Count == 0)
  52. {
  53. this.SizeSet();
  54. }
  55. }
  56.  
  57. void SizeSet()
  58. {
  59. FormBorderStyle fbs = this.FormBorderStyle;
  60. this.FormBorderStyle = FormBorderStyle.None;
  61. Rectangle rect = webBrowser1.Document.Window.Document.Body.ScrollRectangle;
  62. Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
  63. int p = rect.Height / ClientHeight;
  64. int s = rect.Height % ClientHeight;
  65. Bitmap wbmp1 = new Bitmap(rect.Width, ClientHeight, PixelFormat.Format32bppArgb);
  66. using (Graphics g = Graphics.FromImage(bmp))
  67. {
  68. for (int i = 0; i < p; i++)
  69. {
  70. webBrowser1.Document.Window.ScrollTo(0, ClientHeight * i);
  71. this.DrawToBitmap(wbmp1, this.ClientRectangle);
  72. //g.DrawImage(wbmp1, 0, ClientHeight * i);
  73. }
  74. if (s > 0)
  75. {
  76. this.ClientSize = new Size(ClientWidth, s);
  77. webBrowser1.Document.Window.ScrollTo(0, ClientHeight * p);
  78. Bitmap wbmp2 = new Bitmap(rect.Width, s, PixelFormat.Format32bppArgb);
  79. this.DrawToBitmap(wbmp2, this.ClientRectangle);
  80. g.DrawImage(wbmp2, 0, ClientHeight * p);
  81. wbmp2.Dispose();
  82. }
  83. }
  84. wbmp1.Dispose();
  85. this.FormBorderStyle = fbs;
  86. bmp.Save(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\test.png",
  87. ImageFormat.Png);
  88. bmp.Dispose();
  89. }
  90. }
  91. }
  92.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty