http://support.microsoft.com/kb/892462
To Read This,
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.Terms of Use | Trademarks
©2005-©2007 Microsoft Corporation. All rights reserved.
Article ID: 892462 - Last Review: May 31, 2007 - Revision: 1.5
How to use Visual C# to obtain the color of the pixel that is referenced by the mouse pointer
INTRODUCTION
This article describes how to use Microsoft Visual C# to obtain the color of the pixel that is referenced by the mouse pointer.
MORE INFORMATION
To obtain the color of the pixel that is referenced by the mouse pointer by using Visual C#, follow these steps:
- In Microsoft Visual Studio .NET 2003, create a new Visual C#
Windows application. - Add a Label control that is named label1 to capture the pixel color.
- Create a class that contains the Dlllmport statements that are required to call the Microsoft
Windows GDI functions, and then capture an image that represents the current desktop. - Associate the MouseDown event of the label with an event handler that is named label1_MouseDown.
- In the label1_MouseDown event handler, capture an image of the current desktop.
- Associate the MouseUp event of the label with an event handler that is named label1_MouseUp.
- In the label1_MouseUp event handler, retrieve the color that is associated with the current pixel location of the mouse pointer, and then set the BackColor of label1 to the color of the mouse pointer pixel.
- In Visual Studio .NET 2003, create a new Visual C# Windows application.
- Add one Windows Forms Label control to Form1.cs.
- Click the label1 control, and then change the Text property to an empty string.
- Change the BorderStyle property to FixedSingle.
- In the Solution Explorer, right-click Form1.cs, and then click View Code.
- Add the following Using statements to the top of the Form1.cs source code. Note This step adds the required references to call the InteropServices functions and methods.
using System.Runtime.InteropServices;
- Add the following Bitmap variable to Form1.cs at the start of the Form1 class.
private Bitmap myBitmap;
- Add the following Win32APICall class to Form1.cs after the Form1 class.
'기본 카테고리' 카테고리의 다른 글
DELPHI FOR PHP 소개및 한글 사용 방법 (0) | 2009.04.22 |
---|---|
Graphs on Flash - using ActionScript! (0) | 2009.04.21 |
몰래알바로 구입한 새 자가용을 공개합니다. (0) | 2009.04.06 |
2009.03.02 (0) | 2009.03.30 |
인생 반전 연습 (0) | 2009.03.20 |