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. 保存cookie 到本地

    #encoding: utf-8 from urllib import requestfrom http.cookiejar import MozillaCookieJar #创建一个cookieja ...

  2. Win10黑色白色主题切换

    打开设置面板 选择个性化  -> 颜色 -> 选择默认应用模式 然后选择亮和暗就好了. (这还是看404说的我才知道.)

  3. Flume入门案例

    首先需要通过一个配置文件来配置Agent. 通过flume提供的工具启动agent就可以工作了.   (1)编写配置文件 #example.conf:单节点Flume配置 #命名Agent a1的组件 ...

  4. CentOS7下MySQL服务启动失败原因及解决方法

    在重启阿里的CentOS7服务器后,重启MySQL 出现错误 Starting mysqld (via systemctl): Job for mysqld.service failed becaus ...

  5. Laravel-admin form 表单是增加或者修改

    Laravel-admin 实现 form 表单是增加或者修改的三种方法,应用情景:1.新增或者修改 form 展示的表单不同:2.新增或者保存前后回调进行其他的操作 1. use Illuminat ...

  6. JS获取url中的指定参数

    function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new O ...

  7. APP_测试流程(测试点)

    1 APP测试基本流程 1.1流程图 1.2测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试时间. 1.3测试资 ...

  8. 安装docker私有仓库

    先安装docker:http://www.cnblogs.com/cjsblogs/p/8717304.html 安装私有仓库 #下载registry docker pull registry #制作 ...

  9. Keepalived+Nginx+Tomcat 实现高可用Web集群

    https://www.jianshu.com/p/bc34f9101c5e Keepalived+Nginx+Tomcat 实现高可用Web集群 0.3912018.01.08 20:28:59字数 ...

  10. Mysql学习(二)之安装、开启自启、启动、重启、停止

    安装 方法一:通过homebrew brew install mysql 方法二:通过官网dmg文件安装(Mac) https://dev.mysql.com/downloads/mysql/ 通过h ...