效果图:
这是核心代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 取指定点颜色
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]//取设备场景
private static extern IntPtr GetDC(IntPtr hwnd);//返回设备场景句柄
[DllImport("gdi32.dll")]//取指定点颜色
private static extern int GetPixel(IntPtr hdc, Point p);
private void timer1_Tick(object sender, EventArgs e)
{
Point p = new Po