Notification when hover show url

This commit is contained in:
Jaex 2014-01-16 01:36:58 +02:00
parent c734f5c208
commit f3d65825b0

View file

@ -52,12 +52,15 @@ public partial class NotificationForm : Form
private int closingAnimationInterval = 50;
private Font textFont;
private int textPadding = 5;
private int urlPadding = 3;
private Size textRenderSize;
public NotificationForm(int duration, ContentAlignment placement, Size size, Image img, string text, string url)
{
InitializeComponent();
textFont = new Font("Arial", 10);
if (img != null)
{
img = ImageHelpers.ResizeImageLimit(img, size);
@ -67,7 +70,6 @@ public NotificationForm(int duration, ContentAlignment placement, Size size, Ima
}
else if (!string.IsNullOrEmpty(text))
{
textFont = new Font("Arial", 10);
textRenderSize = Helpers.MeasureText(text, textFont, size.Width - textPadding * 2);
size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2);
ToastText = text;
@ -132,6 +134,18 @@ protected override void OnPaint(PaintEventArgs e)
if (ToastImage != null)
{
g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height);
if (mouseInside && !string.IsNullOrEmpty(ToastURL))
{
Rectangle textRect = new Rectangle(0, 0, rect.Width, 40);
using (SolidBrush brush = new SolidBrush(Color.FromArgb(150, 255, 255, 255)))
{
g.FillRectangle(brush, textRect);
}
g.DrawString(ToastURL, textFont, Brushes.Black, textRect.RectangleOffset(-urlPadding));
}
}
else if (!string.IsNullOrEmpty(ToastText))
{
@ -184,6 +198,7 @@ private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
private void NotificationForm_MouseEnter(object sender, EventArgs e)
{
mouseInside = true;
Refresh();
tOpacity.Stop();
Opacity = 1;
@ -192,6 +207,7 @@ private void NotificationForm_MouseEnter(object sender, EventArgs e)
private void NotificationForm_MouseLeave(object sender, EventArgs e)
{
mouseInside = false;
Refresh();
if (durationEnd)
{