In fact, the so-called Windows front color regulator is the use of WinForm forms to cover the entire Windows area. The main requirement is to make the window transparent, and the mouse can click on other programs through the form.
The difficulty is how to let the mouse penetrate the form, the code is also found from the Internet, and now can not find the original link:
The principle is to call the Windows API to set the properties of the window.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
/*
* Author: Billy Qing
* Date: November 20, 2009
* Description: Eyesbaby Windows foreground window.
* Version: 1.0
*/
namespace Eyesbaby
{
public partial class Winscreenadjust:form
{
/*
* The following code is mainly used to invoke the Windows API to implement form transparency (the mouse can penetrate the form)
* Also found on the Internet:
*/
[DllImport ("user32.dll", EntryPoint = "GetWindowLong")]
public static extern long GetWindowLong (IntPtr hwnd, int nindex);
[DllImport ("user32.dll", EntryPoint = "SetWindowLong")]
public static extern long SetWindowLong (IntPtr hwnd, int nindex, long dwnewlong);
[DllImport ("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int setlayeredwindowattributes (IntPtr Handle, int crkey, byte balpha, int dwflags);
const int Gwl_exstyle =-20;
const int ws_ex_transparent = 0x20;
const int ws_ex_layered = 0x80000;
const int lwa_alpha = 2;
public winscreenadjust ()
{
InitializeComponent ();
}
private void Form1_Load (object sender, EventArgs e)
{
//Cancel the form task bar
ShowInTaskbar = false;
//form is at the top of Windows
this. topmost = true;
//Remove form Border
this. FormBorderStyle = Formborderstyle.none;
//Set the maximum size of the form (except for the bottom taskbar section)
this. MaximumSize = new Size (Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
//Set Windows window state to maximized mode
this. WindowState = formwindowstate.maximized;
//Set Windows Properties
SetWindowLong (this. Handle, Gwl_exstyle, GetWindowLong (this. Handle, Gwl_exstyle) | ws_ex_transparent | ws_ex_layered);
SetLayeredWindowAttributes (this. Handle, 0, 128, Lwa_alpha);
}
}
}
As for Eyesbaby, it is easier to set the color portion of a form.
Code:
// 打开颜色选择对话框 ,并分析是否选择了对话框中的确定按钮
if (this.colColorAdjust.ShowDialog() == DialogResult.OK)
{
int[] item=colColorAdjust.CustomColors;
// 将先中的颜色设置为窗体的背景色
this.winAdjust.BackColor = colColorAdjust.Color;
// 保存到配置文件
ConfigHelper.WinForeColor = this.winAdjust.BackColor.Name;
}
Source: http://yizhuqing.cnblogs.com/