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. 【CUDA开发】Thrust库

    Thrust库从C++的STL中得到灵感,将最简单的类似于STL的结构放在Thrust库中,比如STL中的vector.此外,Thrust库还包含STL中的算法和迭代器.        Thrust函 ...

  2. 关于.Net Core+Angular+Ueditor富文本编辑器的使用方式

    博客:https://www.cnblogs.com/24klr/ 资料:https://www.jianshu.com/p/0b21a1324d47 GitHub:https://github.co ...

  3. 第四周课程总结&试验报告2

    试验报告2 写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类 ...

  4. (5.6)mysql高可用系列——MySQL Utilities 管理工具

    关键词:mysql工具集,mysql管理工具,mysql utilities [1]安装mysql utilities cd /download wget https://cdn.mysql.com/ ...

  5. Git 发生Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'.错误

    Git 发生 Unable to create 'D:/Model/test/.git/index.lock': File exists. Another git process seems to b ...

  6. HTML(上)

    目录 HTML(上) 浏览器 HTML 什么是HTML HTML的作用 编写HTML的规范 HTML结构 HTML常用标签 HTML标签速记 HTML(上) 浏览器 浏览器也是一个客户端 #这是一个服 ...

  7. VMware中centos7访问外网配置

    1.配置虚拟机网络适配器,选择NAT模式 2.在编辑->虚拟机网络编辑器->更改设置 选择目前使用的网卡 3.通过ifconfig查看网卡配置 4.编辑网络配置对应上面网卡名称ens33 ...

  8. div+css布局教程(1)

    margin:Margin属性用于设置两个元素之间的距离. 后面如果只有两个参数的话,第一个表示top和bottom,第二个表示left和right因为0 auto,表示上下边界为0,左右则根据宽度自 ...

  9. django 中实现文件下载的3种方式

    方法一:使用HttpResponse from django.shortcuts import HttpResponse def file_down(request): file=open('/hom ...

  10. 使用 java 创建你的第一个区块链(第二部分)

    本系列教程的目的是帮助您了解如何开发区块链技术. 在这第二个教程中,我们将: 创建一个简单的钱包: 使用我们的区块链发送已签名的交易: 感觉更酷. 以上这些将使我们拥有自己的加密货币! 从上一个教程开 ...