Category Archives: CSharp

WebBrowser.DrawToBitmap()

public partial class Form1 : Form
{
WebBrowser wb = new WebBrowser();
public Form1()
{
InitializeComponent();
wb.Height = 100;
wb.Width = 100;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Bitmap bmp = new Bitmap(100, 100);
wb.DrawToBitmap(bmp, new Rectangle(wb.Location.X, wb.Location.Y, wb.Width, wb.Height));
this.pictureBox1.BackgroundImage = bmp;
}
}
ที่มา: http://thepursuitofalife.com/the-missing-drawtobitmap-function-in-the-net-webbrowser-class/

Reading and Writing Text Files

using System;
using System.IO;

class TextFileWriter
{
static void Main(string[] args)
{
// create a writer and open the file
TextWriter tw = new StreamWriter(“date.txt”);

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();
}
}

using System;
using System.IO;

class TextFileReader
{
static void Main(string[] args)
{
// create reader & open file
Textreader tr = new StreamReader(“date.txt”);

// read a line of text
Console.WriteLine(tr.ReadLine());

// close the stream
tr.Close();
}
}
http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

Image Capture Whole Web Page using C#

Image Capture Whole Web Page using C#
http://www.codeproject.com/KB/graphics/IECapture.aspx
Capture Entire Web Page using VB.Net (ทำการ CapturePage ที่ยาวๆ ได้ทั้ง Page เลย)
http://www.codeproject.com/KB/vb/WebCapture.aspx

Screen Capturing
http://www.codeproject.com/kb/graphics/ScreenCaptureByHolzhauer.aspx

TeboScreen: Basic C# Screen Capture Application
http://www.codeproject.com/KB/cs/TeboScreen.aspx

How to: Simulate Mouse and Keyboard Events in Code

How to: Simulate Mouse and Keyboard Events in Code

http://msdn.microsoft.com/en-us/library/ms171548.aspx

SendKeys.Send Method
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

MouseSimulator
http://stackoverflow.com/questions/5094398/how-to-programatically-mouse-move-click-right-click-and-keypress-etc-in-winform

mouse_event function
http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx 
Imitate mouse click
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ebe2c146-03ca-40eb-990d-093fbd3d4886/

Download HTML source in C#

using System.Net;

//...
using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
    client.DownloadFile("http://yoursite.com/page.html", @"C:\localfile.html");

    // Or you can get the file content without saving it:
    string htmlCode = client.DownloadString("http://yoursite.com/page.html");
    //...

}

How can I download HTML source in C#

C# Code Snippet – Download HTML Web Page

WebClient Class