Saturday, 9 July 2011

Print html or any files from Windows form using C#

Using this code you would be able to print any type of pages.
just copy and paste this code on any button event handler.

private void buttonPrint_Click(object sender, EventArgs e)
{
try
{
Process printProc = new Process();

 printProc.StartInfo.FileName =" yourFileName";
printProc.StartInfo.UseShellExecute = true;
printProc.StartInfo.Verb = "print";
printProc.StartInfo.CreateNoWindow = true;
printProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printProc.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Jawed Blog say!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

Thanks,
Md. Jawed

No comments: