Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Windows.Forms
Public Class Toast
Dim colorBackground1 As Color = Color.FromArgb(87, 140, 188)
Dim colorBackground2 As Color = Color.FromArgb(181, 220, 237)
Dim colorRahmen As Color = Color.FromArgb(66, 118, 158)
Dim penRahmen As New Pen(colorRahmen)
Dim imageXButtonInAktiv As Image = Image.FromHbitmap(My.Resources.X_Button_InAktiv.GetHbitmap)
Public Shared Function CreateRoundedRectPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim roundRect As New GraphicsPath
' top line
roundRect.AddLine(rect.Left + radius, rect.Top, _
rect.Right - radius, rect.Top)
' Upper-right corner
roundRect.AddArc(rect.Right - 2 * radius, _
rect.Top, radius * 2, radius * 2, 270, 90)
' right edge
roundRect.AddLine(rect.Right, rect.Top + radius, _
rect.Right, rect.Bottom - 10)
' bottom-right corner
roundRect.AddArc(rect.Right - radius * 2, _
rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90)
' bottom
roundRect.AddLine(rect.Right - 2 * radius, rect.Bottom, _
rect.Left + radius, rect.Bottom)
' bottom-left edge
roundRect.AddArc(rect.Left, rect.Bottom - 2 * radius, _
2 * radius, 2 * radius, 90, 90)
' left side
roundRect.AddLine(rect.Left, rect.Bottom - radius, _
rect.Left, rect.Top + radius)
' upper-left corner
roundRect.AddArc(rect.Left, rect.Top, 2 * radius, _
2 * radius, 180, 90)
Return roundRect
End Function
Dim fontbla As Font
Private Sub Toast_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim myRecTangle As GraphicsPath = CreateRoundedRectPath(New Rectangle(0, 0, 190, 116), 12)
Dim blasds As New LinearGradientBrush(New Rectangle(0, 0, 190, 116), colorBackground1, colorBackground2, LinearGradientMode.Vertical)
e.Graphics.FillPath(blasds, myRecTangle)
e.Graphics.DrawPath(penRahmen, myRecTangle)
e.Graphics.DrawImage(imageXButtonInAktiv, 170, 10)
e.Graphics.DrawString("dsd", fontbla, Brushes.Black, 10, 10)
End Sub
Private Sub Toast_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fontbla = New Font("Arial", 10)
Me.SetDesktopLocation((Screen.PrimaryScreen.Bounds.Width - Me.Size.Width), (Screen.PrimaryScreen.Bounds.Height - Me.Size.Height - 27))
End Sub
Private Sub Toast_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
Timer2.Stop()
Timer1.Start()
End Sub
Private Sub Toast_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
Timer1.Stop()
Timer2.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Opacity = Me.Opacity * 1.25
If Me.Opacity > 0.8 Then
Timer1.Stop()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Me.Opacity = Me.Opacity * 0.75
If Me.Opacity < 0.4 Then
Timer2.Stop()
End If
End Sub
End Class