Web Browser yang bisa unduh
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
public class Form1 : Form
{ [STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentTitleChanged(object sender, EventArgs e)
{
this.Text = webBrowser1.DocumentTitle.ToString();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
webBrowser1.Navigate(textBox1.Text);
}
}
private void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
textBox1.Text = webBrowser1.Url.ToString();
}
private void InitializeComponent()
{
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.textBox1 = new System.Windows.Forms.TextBox();
this.buttonSubmit = new System.Windows.Forms.Button();
this.buttonDownload = new System.Windows.Forms.Button();
this.SuspendLayout();
this.webBrowser1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.webBrowser1.Location = new System.Drawing.Point(12, 28);
this.webBrowser1.MinimumSize = new System.Drawing.Size(1000, 640);
this.webBrowser1.Size = new System.Drawing.Size(700, 339);
this.textBox1.Location = new System.Drawing.Point(14, 4);
this.textBox1.Size = new System.Drawing.Size(399, 20);
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
this.buttonSubmit.Location = new System.Drawing.Point(419, 4);
this.buttonSubmit.Size = new System.Drawing.Size(75, 19);
this.buttonSubmit.Text = "Lihat";
this.buttonSubmit.UseVisualStyleBackColor = true;
this.buttonSubmit.Click += new System.EventHandler(this.buttonSubmit_Click);
this.buttonDownload.Location = new System.Drawing.Point(549, 4);
this.buttonDownload.Size = new System.Drawing.Size(75, 19);
this.buttonDownload.Text = "Unduh";
this.buttonDownload.UseVisualStyleBackColor = true;
this.buttonDownload.Click += new System.EventHandler(this.buttonDownload_Click);
/* this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
*/
this.ClientSize = new System.Drawing.Size(1728, 1430);
this.Controls.Add(this.webBrowser1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.buttonSubmit);
this.Controls.Add(this.buttonDownload);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button buttonSubmit;
private System.Windows.Forms.Button buttonDownload;
private void buttonSubmit_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
}
private void buttonDownload_Click(object sender, EventArgs e)
{
try
{
System.Net.WebClient client = new WebClient();
client.DownloadFile(textBox1.Text, "unduhan.html");
}
catch(Exception d)
{
Console.WriteLine(d.ToString());
};
}
}
No comments:
Post a Comment