110,561
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading;
namespace WindowsApplication194
{
public partial class Form1 : Form, IMessageFilter
{
Button B = new Button();
PictureBox PB = new PictureBox();
Form F = new Form();
GraphicsPath GP = new GraphicsPath();
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(this);
B.Parent = this;
GP.AddEllipse(0, 0, 80, 40);
GP.AddEllipse(20, 45, 40, 15);
GP.AddEllipse(25, 70, 20, 10);
F.Opacity = 0;
F.FormBorderStyle = FormBorderStyle.None;
F.Size = new Size(100, 100);
F.Region = new Region(GP);
F.TopMost = true;
DoDraw(String.Empty);
F.Show();
PB.Parent = F;
PB.Dock = DockStyle.Fill;
}
public bool PreFilterMessage(ref Message m)
{
int WM_MOUSEMOVE = 0x200;
if (m.Msg == WM_MOUSEMOVE)
{
if (B.Bounds.Contains(this.PointToClient(Control.MousePosition)))
{
F.Location = Point.Add(Control.MousePosition, new Size(-25, -F.Height));
F.Show();
new Thread(new ParameterizedThreadStart(ShowFormThread)).Start("ABC");
this.Focus();
}
else
{
F.Opacity = 0;
F.Hide();
}
}
return false;
}
void ShowFormThread(Object Obj)
{
try
{
String Text = Obj.ToString();
int StartTick = Environment.TickCount;
this.Invoke(new Draw(DoDraw), new Object[] { Text });
while ((double)this.Invoke(new GetOpacity(DoGetOpacity)) < 0.8)
if (Environment.TickCount - StartTick > 200)
{
this.Invoke(new IncOpacity(DoIncOpacity));
StartTick = Environment.TickCount;
}
}
catch
{
// 忽略程序退出的异常
}
}
delegate double GetOpacity();
delegate void IncOpacity();
delegate void Draw(String Text);
double DoGetOpacity()
{
return F.Opacity;
}
void DoIncOpacity()
{
F.Opacity += 0.1;
}
void DoDraw(String Text)
{
Bitmap Bmp = new Bitmap(PB.ClientRectangle.Width, PB.ClientRectangle.Height);
using (Graphics G = Graphics.FromImage(Bmp))
{
SizeF SF = G.MeasureString(Text, F.Font);
G.Clear(Color.Yellow);
G.DrawPath(Pens.Black, GP);
G.DrawString(Text, F.Font, Brushes.Black, (80 - SF.Width) / 2, 10);
}
PB.Image = Bmp;
}
}
}