Search This Blog

Monday, January 19, 2015

C# Capture Screen to PictureBox

C# > Drawing > Capture Screen

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
using (MemoryStream s = new MemoryStream())
{
printscreen.Save(s, System.Drawing.Imaging.ImageFormat.Bmp);
       picCapture.Size = new System.Drawing.Size(this.Width, this.Height);
       picCapture.Image = Image.FromStream(s);

}





XmlDocument C# Example

C# > XML > XmlDocument

Represents an XML document.

Example


XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);




NetworkChange Class C#

C# > System.Net > NetworkInformation > NetworkChange

Use this class to receive notification when the IP address of a network interface changes.
Changes can appears when:

  • disconnect network cable
  • out of range of a wireless Local Area Network
  • hardware failure
Events:





    C# NetworkInformation NameSpace

    C# > System.Net > NetworkInformation


    Provides access to network address information and traffic data.

    Classes





    Thursday, January 15, 2015

    ReadAllBytes C# Example

    C# > Files > File Class > ReadAllBytes

    Opens, reads the contents of the file into a byte array, and then closes the file.

    Example

    Read bytes from jpg file and display to PictureBox.

    var bytes = File.ReadAllBytes("D:\\Pics\\1.jpg");
    pictureBox1.Image = Image.FromStream(new System.IO.MemoryStream(bytes));







    C# File Class

    C# > Files > File Class


    Use the File class for:
    • copy, move, rename, create, open, delete to a single file at a time. 
    • get and set file attributes.


    All File methods are static.


    Methods





    Tuesday, January 6, 2015

    IsNumeric equivalent in LINQ example

    C# > LINQ > IsNumeric

    IsNumeric equivalent in LINQ example.

    double value;
    var total = (from DataRow dr in dataTable.Rows
                    where double.TryParse(dr["value"], out value)
                    select Convert.ToDouble(dr["value"])).Sum();