2 using System.Collections.Generic;
3 using System.ComponentModel;
7 using System.Windows.Forms;
8 using System.Diagnostics;
10 using System.Runtime.InteropServices;
12 namespace Lugens.Passer
14 public partial class ToolTipForm : Form
16 private const int SWP_NOSIZE = 1;
17 private const int SWP_NOMOVE = 2;
18 private const int SWP_NOACTIVATE = 0x10;
19 private const int HWND_TOPMOST = -1;
20 private const int GWL_EXSTYLE = -20;
22 private Point drawPoint = new Point(0, 0);
24 //private Size calcSize;
26 private int visibledTime = 0;
27 private int displayedTime = 0;
32 private bool displayed = false;
37 private int duration = 5000;
40 get { return duration; }
41 set { duration = value; }
48 private int startDelay = 200;
51 get { return startDelay; }
52 set { startDelay = value; }
55 private int borderSpace;
56 public int BorderSpace
58 get { return borderSpace; }
62 drawPoint.X = drawPoint.Y = value;
65 private bool alive = true;
68 get { return this.alive; }
71 public ToolTipForm() : this(false)
75 public ToolTipForm(bool top)
78 InitializeComponent();
79 this.Paint += this.OnPaint;
83 protected override void CreateHandle()
86 Win32.SetWindowPos(new HandleRef(this, this.Handle), (IntPtr)HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
89 protected override CreateParams CreateParams
93 CreateParams cp = base.CreateParams;
94 cp.ClassStyle |= 0x00020000;
95 cp.ExStyle |= Win32.WS_EX_NOACTIVATE;
100 protected override bool ShowWithoutActivation
105 private void OnPaint(object sender, PaintEventArgs e)
108 TextRenderer.DrawText(e.Graphics, this.Text, this.Font, this.drawPoint, this.ForeColor, TextFormatFlags.NoPrefix);
109 using(Pen pen = new Pen(this.ForeColor, 1.0F)){
110 e.Graphics.DrawRectangle(pen, 0, 0, this.ClientSize.Width - 1, this.ClientSize.Height - 1);
114 public override string Text
116 get { return base.Text; }
119 int borderSpace = this.borderSpace << 1;
120 base.Text = value.Replace("\t", " ");
121 Size size = TextRenderer.MeasureText(base.Text, this.Font);
122 size.Width += borderSpace;
123 size.Height += borderSpace;
128 public void Show(Point p, int duration, bool fadeIn)
132 this.displayed = false;
133 this.duration = duration;
135 this.visibledTime = System.Environment.TickCount;
136 this.timer1.Enabled = true;
137 //Size size = this.Size;
143 public void Show(string text, Point p, int duration, bool fadeIn)
146 this.Show(p, duration, fadeIn);
149 private void timer1_Tick(object sender, EventArgs e)
151 int tickCount = System.Environment.TickCount;
152 if (tickCount > this.visibledTime + this.startDelay)
155 this.displayedTime = tickCount;
156 this.displayed = true;
157 Size size = this.Size;
162 if (tickCount - this.displayedTime > this.duration)
164 this.Opacity -= Program.FadeInSpeed;
165 if (this.Opacity <= 0D)
167 this.timer1.Enabled = false;
173 if (this.Opacity + Program.FadeInSpeed < Program.FormOpacity)
174 this.Opacity += Program.FadeInSpeed;
176 this.Opacity = Program.FormOpacity;
182 private void ToolTipForm_Resize(object sender, EventArgs e)
187 private void ToolTipForm_FormClosing(object sender, FormClosingEventArgs e)