人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁(yè)面

動(dòng)態(tài)取得當(dāng)前屏幕中光標(biāo)所在位置的顏色

動(dòng)態(tài)取得當(dāng)前屏幕中光標(biāo)所在位置的顏色

更新時(shí)間:2022-06-29 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

//////////////////////////////////////////////////////////////////////////

/// 程序:屏幕取色

/// 功能:動(dòng)態(tài)獲取當(dāng)前屏幕中光標(biāo)所在位置的顏色

/// 作者:黎波

/// 網(wǎng)名:upto(阿球)

/// 郵箱:itfun@163.com

/// 日期:2004年3月31日

//////////////////////////////////////////////////////////////////////////


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace LiBo.ColorPicker
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
// 桌面工作區(qū)的尺寸
Size workingArea;
// Form 的初始位置和在左下角,右下角的位置
Point formLoc, ptLeftBottom, ptRightBottom;

private System.Windows.Forms.Label lblColor;
private System.Windows.Forms.TextBox txtArgb;
private System.Windows.Forms.Timer tmr;
private System.Windows.Forms.ToolTip tip;
private System.ComponentModel.IContainer components;

public Form1()
{
InitializeComponent();

this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.StartPosition = FormStartPosition.CenterScreen;

Rectangle rect = SystemInformation.WorkingArea;
workingArea = new Size(rect.Width, rect.Height);
ptLeftBottom = new Point(0, workingArea.Height - this.Height);
ptRightBottom = new Point(workingArea.Width - this.Width,
workingArea.Height - this.Height);

String tipMsg = "在窗體空白處雙擊鼠標(biāo)左鍵開始取色,按ESC鍵確定顏色";
tip.SetToolTip(this, tipMsg);
tip.SetToolTip(lblColor, tipMsg);
tip.SetToolTip(txtArgb, tipMsg);
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.lblColor = new System.Windows.Forms.Label();
this.tmr = new System.Windows.Forms.Timer(this.components);
this.txtArgb = new System.Windows.Forms.TextBox();
this.tip = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// lblColor
//
this.lblColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblColor.Location = new System.Drawing.Point(8, 8);
this.lblColor.Name = "lblColor";
this.lblColor.TabIndex = 0;
//
// tmr
//
this.tmr.Tick += new System.EventHandler(this.tmr_Tick);
//
// txtArgb
//
this.txtArgb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtArgb.Font = new System.Drawing.Font("Arial", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtArgb.Location = new System.Drawing.Point(8, 40);
this.txtArgb.Name = "txtArgb";
this.txtArgb.TabIndex = 1;
this.txtArgb.Text = "";
this.txtArgb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtArgb_KeyPress);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(115, 70);
this.Controls.Add(this.txtArgb);
this.Controls.Add(this.lblColor);
this.Name = "Form1";
this.Text = "屏幕取色(upto)";
this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

[ DllImport ( "gdi32.dll" ) ]
private static extern bool BitBlt (
IntPtr hdcDest, // 目標(biāo)設(shè)備的句柄
int nXDest, // 目標(biāo)對(duì)象的左上角的X坐標(biāo)
int nYDest, // 目標(biāo)對(duì)象的左上角的X坐標(biāo)
int nWidth, // 目標(biāo)對(duì)象的矩形的寬度
int nHeight, // 目標(biāo)對(duì)象的矩形的長(zhǎng)度
IntPtr hdcSrc, // 源設(shè)備的句柄
int nXSrc, // 源對(duì)象的左上角的X坐標(biāo)
int nYSrc, // 源對(duì)象的左上角的X坐標(biāo)
int dwRop // 光柵的操作值
);

[ DllImport ( "gdi32.dll" ) ]
private static extern IntPtr CreateDC (
string lpszDriver, // 驅(qū)動(dòng)名稱
string lpszDevice, // 設(shè)備名稱
string lpszOutput, // 無(wú)用,可以設(shè)定位"NULL"
IntPtr lpInitData // 任意的打印機(jī)數(shù)據(jù)
);

private void Form1_DoubleClick(object sender, EventArgs e)
{
formLoc = this.Location;
this.Location = ptRightBottom;
this.TopMost = true;
tmr.Enabled = true;
}

private void tmr_Tick(object sender, EventArgs e)

{

// 創(chuàng)建顯示器的DC

IntPtr hdlDisplay = CreateDC("DISPLAY", null, null, IntPtr.Zero);

// 從指定設(shè)備的句柄創(chuàng)建新的 Graphics 對(duì)象

Graphics gfxDisplay = Graphics.FromHdc(hdlDisplay);

// 創(chuàng)建只有一個(gè)象素大小的 Bitmap 對(duì)象

Bitmap bmp = new Bitmap(1, 1, gfxDisplay);

// 從指定 Image 對(duì)象創(chuàng)建新的 Graphics 對(duì)象

Graphics gfxBmp = Graphics.FromImage(bmp);

// 獲得屏幕的句柄

IntPtr hdlScreen = gfxDisplay.GetHdc();

// 獲得位圖的句柄

IntPtr hdlBmp = gfxBmp.GetHdc();

// 把當(dāng)前屏幕中鼠標(biāo)指針?biāo)谖恢玫囊粋(gè)象素拷貝到位圖中

BitBlt(hdlBmp, 0, 0, 1, 1, hdlScreen, MousePosition.X, MousePosition.Y, 13369376);

// 釋放屏幕句柄

gfxDisplay.ReleaseHdc(hdlScreen);

// 釋放位圖句柄

gfxBmp.ReleaseHdc(hdlBmp);

lblColor.BackColor = bmp.GetPixel(0, 0); // 獲取像素的顏色

txtArgb.Text = "0x" + lblColor.BackColor.ToArgb().ToString("x").ToUpper();

gfxDisplay.Dispose();
gfxBmp.Dispose();

bmp.Dispose(); // 釋放 bmp 所使用的資源

}



private void txtArgb_KeyPress(object sender, KeyPressEventArgs e)
{
// 當(dāng)按下ESC鍵時(shí),確定所取的顏色ARGB值
// 注意:只有當(dāng)窗體處于激活狀態(tài)時(shí)才有效
if (e.KeyChar == (char)Keys.Escape)
{
tmr.Enabled = false;
this.Location = formLoc;
this.TopMost = false;
txtArgb.SelectAll();
}
}

private void Form1_MouseEnter(object sender, EventArgs e)
{
if (this.Location == ptLeftBottom) //窗體在左下角
{
this.Location = ptRightBottom;
}
else if (this.Location == ptRightBottom) // 窗體在右下角
{
this.Location = ptLeftBottom;
}
}

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 师宗县| 武隆县| 阳西县| 调兵山市| 吕梁市| 衡南县| 裕民县| 三台县| 英超| 元阳县| 永福县| 南漳县| 临颍县| 稷山县| 东阿县| 靖安县| 台中市| 太康县| 张家川| 防城港市| 偏关县| 仲巴县| 茶陵县| 南部县| 天水市| 桐城市| 佛山市| 三原县| 巴楚县| 拜泉县| 武汉市| 阆中市| 崇义县| 广安市| 登封市| 静安区| 鄂尔多斯市| 连江县| 南陵县| 安康市| 荣昌县|