class AlphaBlend { // Methods public AlphaBlend() { } public void AlphaBlendNumber(IntPtr Handle, short Num) { AlphaBlend.SetLayeredWindowAttributes(Handle, 0, (byte)Num, 2); } public void AlphaBlendPercent(IntPtr Handle, short Percent) { AlphaBlend.SetLayeredWindowAttributes(Handle, 0, (byte)Math.Round((double)((((double)Percent) / 100) * 255)), 2); } public IntPtr FindApplicationWindow([Optional] string WindowClass /* = null */, [Optional] string WindowTitle /* = null */) { return AlphaBlend.FindWindow(WindowClass, WindowTitle); } [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] private static extern int GetWindowLong(IntPtr Handle, int nIndex); public void ResetAlphaBlending(IntPtr Handle) { int num1 = AlphaBlend.GetWindowLong(Handle, -20); // The following line has me stumped, in VB, the const WS_EX_LAYERED breaks down to the value 524288 // Yet on the line below is the same number but increased by one, basically it should (boolean here) num1 and not WS_EX_LAYERED AlphaBlend.SetWindowLong(Handle, -20, num1 & -524289); } [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags); public void SetupAlphaBlending(IntPtr Handle) { int num1 = AlphaBlend.GetWindowLong(Handle, -20); num1 |= WS_EX_LAYERED; AlphaBlend.SetWindowLong(Handle, -20, num1); } [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] private static extern int SetWindowLong(IntPtr Handle, int nIndex, int dwNewLong); // Fields private const short GWL_EXSTYLE = -20; private const short LWA_ALPHA = 2; private const short LWA_COLORKEY = 1; private const int WS_EX_LAYERED = 0x80000; } 这个我用了一下,用form的handle就可以,但是用控件的handle没反应,难道只能重绘么? 重绘的话,我的控件是能移动的估计肯定要闪屏啊 !
两个图片一个框,一个是内容,叠起来就 有了呗!
有人说用 SetLayeredWindowAttribute
但小子才疏学浅,搞不懂!
我主要是做LED屏幕的
{
// Methods
public AlphaBlend()
{
} public void AlphaBlendNumber(IntPtr Handle, short Num)
{
AlphaBlend.SetLayeredWindowAttributes(Handle, 0, (byte)Num, 2);
} public void AlphaBlendPercent(IntPtr Handle, short Percent)
{
AlphaBlend.SetLayeredWindowAttributes(Handle, 0, (byte)Math.Round((double)((((double)Percent) / 100) * 255)), 2);
} public IntPtr FindApplicationWindow([Optional] string WindowClass /* = null */, [Optional] string WindowTitle /* = null */)
{
return AlphaBlend.FindWindow(WindowClass, WindowTitle);
} [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowLong(IntPtr Handle, int nIndex); public void ResetAlphaBlending(IntPtr Handle)
{
int num1 = AlphaBlend.GetWindowLong(Handle, -20);
// The following line has me stumped, in VB, the const WS_EX_LAYERED breaks down to the value 524288
// Yet on the line below is the same number but increased by one, basically it should (boolean here) num1 and not WS_EX_LAYERED
AlphaBlend.SetWindowLong(Handle, -20, num1 & -524289);
} [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags); public void SetupAlphaBlending(IntPtr Handle)
{
int num1 = AlphaBlend.GetWindowLong(Handle, -20);
num1 |= WS_EX_LAYERED;
AlphaBlend.SetWindowLong(Handle, -20, num1);
} [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int SetWindowLong(IntPtr Handle, int nIndex, int dwNewLong);
// Fields
private const short GWL_EXSTYLE = -20;
private const short LWA_ALPHA = 2;
private const short LWA_COLORKEY = 1;
private const int WS_EX_LAYERED = 0x80000; }
这个我用了一下,用form的handle就可以,但是用控件的handle没反应,难道只能重绘么?
重绘的话,我的控件是能移动的估计肯定要闪屏啊 !