This program was written when I went to school. It happened several years ago. When I sorted out hard drive files a few days ago, I found that I actually wrote a lot of things, but I didn't mix them in the garden at the time, so there is no way to share it. If you have time, share it with your friends. My main implementation ideas are:
1. Create a canvas (that is, Form) with the same size as the current screen.
2. Create a drawing object on the canvas and copy the content of the current screen.
3. Use the GetThumbnailImage method of the Image object to obtain a 20-pixel Image of the mouse coordinate point, and then zoom in the Image as a thumbnail to achieve the magnifier effect.
4. Use the API to obtain the pixel color of the current mouse coordinate point
V. Real-time tracking of the color-absorbing Display Information Form
6. the arrow key fine-tuning function allows you to directly call WIN's API to set mouse coordinates.
Let's take a look at the attraction effect:
Control layout:
Logic Thinking diagram of real-time tracking form display mode:
The form is always in the shown state (top left, top right, bottom left, and bottom right). The implementation code is as follows:
Point p = new Point ();
P. X = MousePosition. X + 10;
P. Y = MousePosition. Y + 10;
Size s = Screen. PrimaryScreen. Bounds. Size;
If (p. X> s. Width-this. Width)
P. X-= this. Width + 20;
If (p. Y> s. Height-this. Height)
P. Y-= this. Height + 20;
This. Location = p;
Now, I will attach all my code below:
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Namespace LR. Tools
{
/// <Summary>
/// Summary of LR. Tools
/// Program: LR. Tools V1.0
/// Developer: werewolf
// QQ: 459094521 blog: http://www.cnblogs.com/waw/
/// Compilation Time:
/// <Summary>
Public partial class WinEatColor: LR. Tools. MasterForm
{
Form f = new Form ();
Public WinEatColor ()
{
F. FormBorderStyle = FormBorderStyle. None; // no border
F. Cursor = System. Windows. Forms. Cursors. Cross;
F. WindowState = FormWindowState. Maximized;
F. Opacity = 0.01;
F. ShowInTaskbar = false;
F. Show ();
InitializeComponent ();
}
Private void timereffectick (object sender, EventArgs e)
{
// Coordinates of the mouse
This. label1.Text = "mouse coordinates:" + MousePosition. X + "," + MousePosition. Y;
// Display handle
This. label3.Text = "handle:" + LR. Win32API. WindowAPI. WindowFromPoint (MousePosition );
// The current form automatically follows the mouse
This. MoveForm ();
// Use the API to obtain the pixel color of the current mouse coordinate point
Color c = LR. Win32API. WindowAPI. GetColorOfScreen (MousePosition );
// Code displayed on the webpage
This. textBox1.Text = "#" + c. Name. ToUpper (). Substring (2 );
// Display RGB three colors
This.txt _ RGB. Text = c. R. ToString () + "," + c. G. ToString () + "," + c. B. ToString ();
// Set the label color
This. label6.BackColor = c;
// Display magnifiers
This. ShowPictureBox (MousePosition );
}
Void ShowPictureBox (Point p)
{
// Create a canvas with the same size as the current screen
Bitmap bmp = new Bitmap (20, 20 );
// Create a drawing object on the canvas
Graphics g = Graphics. FromImage (bmp );
// Capture and copy the current Screen Content
G. CopyFromScreen (p. X-10, p. Y-10, bmp. Size );
// Magnifiers in the form of thumbnails
Image pThumbnail = bmp. GetThumbnailImage (this. pictureBox1.Width, this. pictureBox1.Height, null, new IntPtr ());
// Enlarge the image
G. DrawImage (bmp, 10, 10, pThumbnail. Width, pThumbnail. Height );
G. Dispose ();
This. pictureBox1.Image = pThumbnail;
G = Graphics. FromImage (this. pictureBox1.Image );
G. DrawRectangle (Pens. Black, this. pictureBox1.Width/2-5, this. pictureBox1.Height/2-5, 10, 10 );
G. Dispose ();
}
Void MoveForm ()
{
Point p = new Point ();
P. X = MousePosition. X + 10;
P. Y = MousePosition. Y + 10;
Size s = Screen. PrimaryScreen. Bounds. Size;
If (p. X> s. Width-this. Width)
P. X-= this. Width + 20;
If (p. Y> s. Height-this. Height)
P. Y-= this. Height + 20;
This. Location = p;
}
Private void WinEatColor_Load (object sender, EventArgs e)
{
}
Private void WinEatColor_KeyUp (object sender, KeyEventArgs e)
{
If (e. KeyCode = Keys. Escape)
This. timer1.Stop ();
Point pCur = MousePosition;
// Fine-tune the direction keys
If (e. KeyCode = Keys. Up)
LR. Win32API. WindowAPI. SetCursorPos (pCur. X, pCur. Y-1 );
If (e. KeyCode = Keys. Left)
LR. Win32API. WindowAPI. SetCursorPos (pCur. X-1, pCur. Y );
If (e. KeyCode = Keys. Right)
LR. Win32API. WindowAPI. SetCursorPos (pCur. X + 1, pCur. Y );
If (e. KeyCode = Keys. Down)
LR. Win32API. WindowAPI. SetCursorPos (pCur. X, pCur. Y + 1 );
}
Private void WinEatColor_Deactivate (object sender, EventArgs e)
{
This. timer1.Stop ();
}
// Refresh
Private void button#click (object sender, EventArgs e)
{
This. timer1.Start ();
}
Private void textbox#mouseenter (object sender, EventArgs e)
{
This. textBox1.Focus ();
This. textBox1.SelectAll ();
This. textBox1.Copy ();
}
Private void picturebox#mousedown (object sender, MouseEventArgs e)
{
LR. Win32API. WindowAPI. MouseMoveWindow (this. Handle );
}
Private void WinEatColor_FormClosed (object sender, FormClosedEventArgs e)
{
F. Close ();
}
}
}
From: Ai Wei from blog