1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Runtime.InteropServices;
 10 
 11 namespace GetScrColor
 12 {
 13     public partial class Form1 : Form
 14     {
 15         public Form1()
 16         {
 17             InitializeComponent();
 18         }
 19 
 20         private bool flag = false;
 21 
 22         public struct POINTAPI
 23         {
 24             public uint x;
 25             public uint y;
 26         }
 27 
 28         public class WinInfo
 29         {
 30             [DllImport("user32.dll")]
 31             public static extern uint WindowFromPoint
 32             (
 33                 uint x_point,
 34                 uint y_point
 35             );
 36 
 37             [DllImport("user32.dll")]
 38             public static extern bool GetCursorPos
 39             (
 40                 ref POINTAPI p
 41             );
 42 
 43             [DllImport("user32.dll")]
 44             public static extern uint ScreenToClient
 45             (
 46                 uint hwnd,
 47                 ref POINTAPI p
 48             );
 49 
 50             [DllImport("user32.dll")]
 51             public static extern uint GetDC
 52             (
 53                 uint hwnd
 54             );
 55 
 56             [DllImport("gdi32.dll")]
 57             public static extern uint GetPixel
 58             (
 59                 uint hDC,
 60                 uint x,
 61                 uint y
 62             );
 63 
 64             [DllImport("user32.dll")]
 65             public static extern uint ReleaseDC
 66             (
 67                 uint hwnd,
 68                 uint hdc
 69             );
 70         }
 71 
 72         private void Form1_Load(object sender, EventArgs e)
 73         {
 74             InitPos(0,0,false);
 75             Screen s = Screen.PrimaryScreen;
 76             Rectangle r = s.Bounds;
 77             int iWidth = r.Width;
 78             int iHeight = r.Height;
 79             //创建一个和屏幕一样大的bitmap
 80             Image img = new Bitmap(iWidth,iHeight);
 81             //从一个继承自image类的对象中创建Graphics对象
 82             Graphics g = Graphics.FromImage(img);
 83             //抓取全屏幕
 84             g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
 85             this.WindowState = FormWindowState.Maximized;
 86             this.BackgroundImage = img;
 87         }
 88 
 89         private void Form1_MouseMove(object sender, MouseEventArgs e)
 90         {
 91             POINTAPI Papi = new POINTAPI();
 92             WinInfo.GetCursorPos(ref Papi);
 93             uint v_hwnd = WinInfo.WindowFromPoint(Papi.x, Papi.y);
 94             uint v_DC = WinInfo.GetDC(v_hwnd);
 95             WinInfo.ScreenToClient(v_hwnd, ref Papi);
 96             uint v_Color = WinInfo.GetPixel(v_DC, Papi.x, Papi.y);
 97 
 98             uint v_Red, v_Green, v_Blue;
 99             v_Red = v_Color & 0xff;
100             v_Green = (v_Color & 0xff00) / 256;
101             v_Blue = (v_Color & 0xff0000) / 65536;
102 
103             this.txtRGB.Text ="#"+v_Red.ToString("x").PadLeft(2, '0') + v_Green.ToString("x").PadLeft(2, '0') + v_Blue.ToString("x").PadLeft(2, '0');
104             this.txtRGBDesc.Text = v_Red.ToString("d") + " " + v_Green.ToString("d") + " " + v_Blue.ToString("d");
105             this.txtShow.BackColor = Color.FromArgb((int)v_Red, (int)v_Green, (int)v_Blue);
106             WinInfo.ReleaseDC(v_hwnd, v_DC);
107         }
108 
109         private void InitPos(int x,int y,bool bFlag)
110         {
111             panel1.Left = x;
112             panel1.Top = y;
113             flag = bFlag;
114         }
115 
116 
117         private void panel1_MouseEnter(object sender, EventArgs e)
118         {
119             if (!flag)
120             {
121                 InitPos(this.Width - panel1.Width, 0, true);
122             }
123             else
124             {
125                 InitPos(0, 0, false);
126             }
127         }
128 
129         private void Form1_KeyDown(object sender, KeyEventArgs e)
130         {
131             if (e.KeyCode == Keys.Escape)
132             {
133                 this.Close();
134             }
135         }
136 
137     }
138 }
139

C#制作的屏幕取色器的更多相关文章

  1. TakeColor 屏幕取色器 8.0 中文绿色版

    软件名称: TakeColor 屏幕取色器软件语言: 简体中文授权方式: 免费软件运行环境: Win8 / Win7 / Vista / WinXP软件大小: 210KB图片预览: 软件简介:使用方便 ...

  2. ColorPix——到目前为止最好用的屏幕取色器

    分享一个颜色取色器网页.PPT.EXCEL配色不再烦恼 简单易用 大家做商业.企业报告的时候是不是经常遇到要调色的困扰呢?PPT.EXCEL等颜色选取会对报告有质的影响!!要更专业要更有美感!给大家分 ...

  3. powerpoint取色器有什么用|ppt取色器使用教程

    在使用powerpoint过程中常常发现一些功能我们很少用到,其实是自己不会用的原因,关于powerpoint取色器有什么用呢?接下来我们一起来学一下ppt取色器使用教程. powerpoint取色器 ...

  4. C#取色器

    闲来无事,就写了一个取色器.原理其实很简单,只需要两步, 获取鼠标光标的位置, 获取当前鼠标光标的位置的RGB颜色值. 获取鼠标光标的位置: System.Drawing.Point p = Mous ...

  5. Arava: 用 swing 写一个取色器

    备哥以前发我了一个小工具,TakeColor 取色器.来复刻一个吧. 分析一下:顶部是菜单,左侧框显示当前鼠标所在的颜色(下面显示当前坐标和颜色值,默认RGB),中间框显示鼠标周围区域,右侧显示取色的 ...

  6. 屏幕取色工具推荐 ColorPix

    很好用的一个屏幕取色工具,方便套页面时,在图片上取色. 用鼠标指到取色未知,按CTRL+C,就可复制16进制的颜色值. 下载地址:http://files.cnblogs.com/zjfree/Col ...

  7. Win10手记-取色器ColorPicker的实现

    最近个人项目需要用到ColorPicker,但是适用于WinRT和Win10的基本没用,所以只能自己造轮子了. 平台环境 Windows 10 Visual Studio 2015 思路 确定需求后, ...

  8. 如何使用屏幕取色工具ColorPixl

    ColorPix可以屏幕取色,假如现在想要取色桌面徽标键的颜色,按任意键可以锁定这个区域(press any key to lock)这样我们就可以在放大的区域更清楚的取色,加号按钮可以设置该软件是否 ...

  9. Delphi制作QQ自动登录器源码

    Delphi制作QQ自动登录器源码  http://www.cnblogs.com/sunsoft/archive/2011/02/25/1964967.html 以TM2009为例,检查了一下,未登 ...

随机推荐

  1. SQL- 将一张表的数据插入到另一张表,表结构不一致(加条件)

    公司业务需要,在对表进行操作的时候将操作人和操作记录记录到日志表里.记录下来以供参考和学习. 首先准备两张测试表:Info以及InfoLog 1.表结构相同的情况下: insert into Info ...

  2. 【Python基础】lpthw - Exercise 46 项目骨架

    本节将会介绍如何构建一个项目骨架目录.骨架目录中会包含项目文件布局.自动测试代码.模块及安装脚本. 一.环境配置(win10) 1. 检查并确认自己只安装了一个python版本. cd ~ pytho ...

  3. 'Python.exe' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    说明python不能被调用,需要为他制定正确的路径.0=0(win10想要打开任何东西,左下角搜索框) 1.打开 python,输入import os 输入os.getcwd,得到路径. 2.打开 编 ...

  4. 【Linux开发】linux设备驱动归纳总结(九):1.platform总线的设备和驱动

    linux设备驱动归纳总结(九):1.platform总线的设备和驱动 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  5. HTML笔记(三) 表格和列表

    本篇记录表格 (table) 和有序列表 (ordered list) \ 无序列表 (unordered list) 的部分用法 1.表格table 表格标签 使用 <table> 定义 ...

  6. 【Linux-驱动】简单字符设备驱动结构和初始化

    (1)在编写简单字符设备驱动的时候,首先要申请一个设备结构struct cdev: struct cdev { struct kobject kobj; struct module *owner; / ...

  7. 【pytorch】学习笔记(二)- Variable

    [pytorch]学习笔记(二)- Variable 学习链接自莫烦python 什么是Variable Variable就好像一个篮子,里面装着鸡蛋(Torch 的 Tensor),里面的鸡蛋数不断 ...

  8. Centos8 重启网卡方法

    问题情况: 1.虚机centos8 修改为静态ip后,由于网卡网段变更,无法上网 2.最小化安装,没有ifconfig 3.firewalld,selinux关闭 4.ping 不通物理机 根本原因: ...

  9. JavaScript更改css样式

    来源:https://www.w3school.com.cn/js/js_htmldom_css.asp 1, document.getElementById(id).style.property = ...

  10. java 如何编写多线程的代码

    线程是干活的所以线程一定是Thread,或者改线程实现Runnable接口多线程是竞争关系,所以多个线程竞争同一个资源,也就是同一个对象所以这个竞争对象发到Thread中即: // resources ...