基本信息
源码名称:C# 通过鼠标获取任意位置的坐标和颜色(可用作屏幕颜色抓取)
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2016-09-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
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
{
[DllImport("user32.dll")]//取设备场景
private static extern IntPtr GetDC(IntPtr hwnd);//返回设备场景句柄
[DllImport("gdi32.dll")]//取指定点颜色
private static extern int GetPixel(IntPtr hdc, Point p);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Timer tim = new Timer();
tim.Interval = 1;
tim.Tick = delegate
{
Point p = new Point(MousePosition.X, MousePosition.Y);//取置顶点坐标
IntPtr hdc = GetDC(new IntPtr(0));//取到设备场景(0就是全屏的设备场景)
string txtStartX = MousePosition.X.ToString();
string txtStartY = MousePosition.Y.ToString();
toolStripStatusLabel1.Text ="坐标位置:X:" txtStartX ",Y:" txtStartY;
int c = GetPixel(hdc, p);//取指定点颜色
int r = (c & 0xFF);//转换R
int g = (c & 0xFF00) / 256;//转换G
int b = (c & 0xFF0000) / 65536;//转换B
pictureBox1.BackColor = Color.FromArgb(r, g, b);
toolStripStatusLabel2.Text = "RGB:R:" r.ToString() ",G:" g.ToString() ",B:" b.ToString();
};
tim.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult TS = MessageBox.Show("您确认要确认退出吗?", "系统消息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (TS == DialogResult.Yes)
{
// e.Cancel = false;
// Application.Exit();
Application.ExitThread();
}
else
{
e.Cancel = true;
}
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar = false;
//this.notifyIcon.Visible = true;
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
//notifyIcon.Visible = false;
this.ShowInTaskbar = true;
}
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
try
{
//最小化
if (this.WindowState == FormWindowState.Minimized)
{
//不显示窗体
this.ShowInTaskbar = false;
//托盘可见
this.notifyIcon1.Visible = true;
//气球提示
this.notifyIcon1.ShowBalloonTip(3, "提示", "系统仍在运行!\n如要打开,请点击图标", ToolTipIcon.Info);
}
}
catch (Exception ex)
{
}
}
}
}