Дочерние формы, как сделать, чтобы они были разной прозрачности? - C#
Формулировка задачи:
как в Paint.net
Решение задачи: «Дочерние формы, как сделать, чтобы они были разной прозрачности?»
textual
Листинг программы
public class Transparency
{
const int GWL_EXSTYLE = -20;
const int WS_EX_LAYERED = 0x80000;
const int LWA_COLORKEY = 1;
const int LWA_ALPHA = 2;
IntPtr hwnd;
public Transparency(IntPtr hwnd)
{
this.hwnd = hwnd;
}
~Transparency()
{
ClearTransparency();
}
public bool SetAlphaTransparency(byte alpha)
{
return SetTransparency(0, alpha, LWA_ALPHA);
}
public bool SetTransparencyColor(uint rgb)
{
return SetTransparency(rgb, 0, LWA_COLORKEY);
}
public bool SetTransparency(uint rgb, byte alpha)
{
return SetTransparency(rgb, alpha,
LWA_COLORKEY | LWA_ALPHA);
}
public bool SetTransparency(uint rgb, byte alpha, uint flags)
{
if (!IsWindow(hwnd)) return false;
int exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
if (SetWindowLong(hwnd, GWL_EXSTYLE,
exstyle | WS_EX_LAYERED)) {
if (SetLayeredWindowAttributes(hwnd, rgb, alpha, flags))
return true;
}
return false;
}
public bool ClearTransparency()
{
if (!IsWindow(hwnd)) return false;
int exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
return (SetWindowLong(hwnd, GWL_EXSTYLE,
exstyle ^ WS_EX_LAYERED));
}
[DllImport("user32.dll")]
static extern bool IsWindow(IntPtr hwnd);
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd,
uint crKey, byte bAlpha, uint dwFlags);
[DllImport("user32.dll")]
static extern bool SetWindowLong( IntPtr hwnd,
int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hwnd, int nIndex);
}