Reading and writing a pixel color to the API help

Import System.Drawing namespace ,System.Runtime.InteropServices and System.Windows.Forms namespace .

using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
[DllImport( "user32.dll" )]
static extern IntPtr GetDC( IntPtr hWnd );
[DllImport( "user32.dll" )]
static extern int ReleaseDC( IntPtr hWnd, IntPtr hDC );
[DllImport( "gdi32.dll" )]
static extern int GetPixel( IntPtr hDC, int x, int y );
[DllImport( "gdi32.dll" )]
static extern int SetPixel( IntPtr hDC, int x, int y, int color );

static public Color GetPixel( Control control, int x, int y )
{
    Color color = Color.Empty;
    if (control != null)
    {
        IntPtr hDC = GetDC( control.Handle );
        int colorRef = GetPixel( hDC, x, y );
        color = Color.FromArgb(
            (int)(colorRef & 0x000000FF),
            (int)(colorRef & 0x0000FF00) >> 8,
            (int)(colorRef & 0x00FF0000) >> 16 );
        ReleaseDC( control.Handle, hDC );
    }
    return color;
}
static public void SetPixel( Control control, int x, int y, Color color )
{
    if (control != null)
    {
        IntPtr hDC = GetDC( control.Handle );
        int argb = color.ToArgb();
        int colorRef =
            (int)((argb & 0x00FF0000) >> 16) |
            (int)(argb & 0x0000FF00) |
            (int)((argb & 0x000000FF) << 16);
        SetPixel( hDC, x, y, colorRef );
        ReleaseDC( control.Handle, hDC );
    }
}

Collection Initilize NET 3.0 to up

Collection can I set the same time also to define.
Example 1

List<string> names = new List<string> {"Jack", "bill", "marin", "Sam"};

Example 2 – the assumption having class like:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
}

Can write:

List<Person> people = new List<Person> {
    new Person { FirstName = "Bill", LastName = "Gates", Age = 50 },
    new Person { FirstName = "Angelina", LastName = "Jolie", Age = 32 },
    new Person { FirstName = "Barack", LastName = "Obama", Age = 48}
};

Only the sample program can be run (using the Process) C#

Only the sample program can be run (using the Process)
Import using System.Diagnostics namespace

using System.Diagnostics;

These changes in the class apply to the StartUp program:

static class Program
{
    [STAThread]
    static void Main()
    {
        if (IsPrevInstance())
            return;
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    private static bool IsPrevInstance()
    {
        string processName = Process.GetCurrentProcess().ProcessName;
        Process[] instances = Process.GetProcessesByName(processName);
        if (instances.Length > 1)
            return true;
        else
            return false;
    }
}

Capture and import of screen C#

Add a Button and change its name to GetCapture and write this below code on Button’s Click event handler.

private void GetCapture_Click(object sender, EventArgs e)
{
this.BackgroundImage= CaptureScreen();
}

Write this below code on class Form

private Image CaptureScreen()
{
Bitmap screen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
using (Graphics g = Graphics.FromImage(screen))
{
g.CopyFromScreen(0, 0, 0, 0, screen.Size);
}
return screen;
}