using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 常量
private const int Flags常量 = 2;
#endregion
#region DLL函数定义
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
public static extern int SetWindowLong(IntPtr hwnd,int nIndex,int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, int crKey,byte bAlpha, int dwFlags);
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr hwnd,int nIndex);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
#endregion
#region 全局变量
private IntPtr m_int窗口句柄 = IntPtr.Zero;
#endregion
#region 事件
private void Form1_Load(object sender, EventArgs e)
{
int o_int窗口信息 = 0;
m_int窗口句柄 = this.Handle;
o_int窗口信息 = GetWindowLong(m_int窗口句柄, -20);
o_int窗口信息 = (o_int窗口信息 | 524288);
SetWindowLong(m_int窗口句柄, -20, o_int窗口信息);
SetLayeredWindowAttributes(m_int窗口句柄, 0, 100, Flags常量);
timer2.Interval = 50;
timer2.Start();
this.Left = Screen.PrimaryScreen.Bounds.Width - 200;
this.Top = Screen.PrimaryScreen.Bounds.Height;
timer1.Interval = 50;
timer1.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
int a = 255;
IntPtr o_int窗口句柄 = this.Handle;
int o_int窗口信息 = GetWindowLong(m_int窗口句柄, -20);
o_int窗口信息 = (o_int窗口信息 | 524288);
SetWindowLong(m_int窗口句柄, -20, o_int窗口信息);
SetLayeredWindowAttributes(o_int窗口句柄, 0, (byte)a, Flags常量);
while (a > 50)
{
a = a - 20;
SetLayeredWindowAttributes(o_int窗口句柄, 0, (byte)a, Flags常量);
System.Threading.Thread.Sleep(100);
}
this.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
int a = 0;
while (a != 250)
{
a = a + 50;
SetLayeredWindowAttributes(m_int窗口句柄, 0, (byte)a, Flags常量);
System.Threading.Thread.Sleep(100);
}
timer1.Stop();
}
private void timer2_Tick(object sender, EventArgs e)
{
if (this.Top < Screen.PrimaryScreen.Bounds.Height - 200)
{
timer2.Stop();
}
this.Top = this.Top - 8;
}
#endregion
private void label1_Click(object sender, EventArgs e)
{
}
}
}
==========================
感觉dll在c#里调用很不方便(也可能是功能强大的原因?)
另外,我觉得不用dll也完全可以达到这样的效果吧???
用坐标和透明度属性应该就可以.