C# กับการ Capture Screen || Run the application at Windows startup (2009-08-27)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Rectangle screenRect = Screen.PrimaryScreen.WorkingArea;
Bitmap dumpBitmap = new Bitmap(screenRect.Width, screenRect.Height);
using (Graphics targetGraphics = Graphics.FromImage(dumpBitmap))
{
targetGraphics.CopyFromScreen(0, 0, 0, 0, new Size(dumpBitmap.Width, dumpBitmap.Height));
}
// Save ti dist
dumpBitmap.Save(@"C:/test.png", dumpBitmap.RawFormat);
//show in picture box
//this.pictureBox1.BackgroundImage = dumpBitmap;
//this.pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
}
}
}
แถมอีกนิด
Run the application at Windows startup
The full path to it is HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run or if you want the setting for all the users of the
| operating system use HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. |
using Microsoft.Win32;
// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
// Add the value in the registry so that the application runs at startup
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());
// Remove the value from the registry so that the application doesn't start
rkApp.DeleteValue("MyApp", false);
// Check to see the current state (running at startup or not)
if (rkApp.GetValue("MyApp") == null)
{
// The value doesn't exist, the application is not set to run at startup
chkRun.Checked = false;
}
else
{
// The value exists, the application is set to run at startup
chkRun.Checked = true;
}
|