Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '# created by tuttomax
- Public Class MyBaloon : Inherits System.ComponentModel.Component
- Private masterH As Integer = My.Computer.Screen.WorkingArea.Height
- Private masterW As Integer = My.Computer.Screen.WorkingArea.Width
- #Region "Inizializzo oggetti"
- Sub New()
- CreateFormBallonStandard()
- End Sub
- #Region "FormBallon"
- Private WithEvents FormBallon As New Form
- #Region "Propietà"
- Private _Width As Integer = 250
- Public Property Width As Integer
- Get
- Return _Width
- End Get
- Set(value As Integer)
- _Width = value
- FormBallon.Width = _Width
- End Set
- End Property
- Private _Height As Integer = 50
- Public Property Height As Integer
- Get
- Return _Height
- End Get
- Set(value As Integer)
- _Height = value
- FormBallon.Height = _Height
- End Set
- End Property
- Private _Image As Image
- Public Property Image As Image
- Get
- Return _Image
- End Get
- Set(value As Image)
- _Image = value
- End Set
- End Property
- Enum ETipo
- Movimento
- Opacità
- End Enum
- Private _Tipo As ETipo = ETipo.Movimento
- Public Property Tipo As ETipo
- Get
- Return _Tipo
- End Get
- Set(value As ETipo)
- _Tipo = value
- End Set
- End Property
- Private _Velocità As Integer = 10
- Public Property VelocitàMovimento As Integer
- Get
- Return _Velocità
- End Get
- Set(value As Integer)
- _Velocità = value
- End Set
- End Property
- Private _ChiudiDopo As Integer = 1000
- Public Property ChiudiDopo As Integer
- Get
- Return _ChiudiDopo
- End Get
- Set(value As Integer)
- _ChiudiDopo = value
- End Set
- End Property
- #End Region
- Private Sub CreateFormBallonStandard()
- With FormBallon
- .Width = Width
- .Height = Height
- .FormBorderStyle = FormBorderStyle.None
- .Location = New Point(masterW - FormBallon.Width, masterH)
- .Show()
- .Hide()
- End With
- End Sub
- Private Sub OnPaintBallonForm(ByVal sender As Object, e As PaintEventArgs) Handles FormBallon.Paint
- Dim W As Integer = FormBallon.Width
- Dim H As Integer = FormBallon.Height
- 'QUI VA CAMBIATA LA GRAFICA
- Dim masterRectangle As New Rectangle(0, 0, W, H)
- e.Graphics.FillRectangle(Brushes.Red, masterRectangle)
- If Not Image Is Nothing Then Dim NewImage As New Bitmap(Image, 36, 36) : e.Graphics.DrawImage(NewImage, 5, 10)
- End Sub
- #End Region
- #End Region
- #Region "Animazione"
- #Region "Delegati"
- Private Delegate Sub delegateShow()
- Private delegatoShow As New delegateShow(AddressOf Show)
- Private Sub Show()
- FormBallon.Show()
- End Sub
- Private Delegate Sub delegateLocation(c As Control, x As Integer, y As Integer)
- Private delegatoLocation As New delegateLocation(AddressOf Location)
- Private Sub Location([Control] As Control, x As Integer, y As Integer)
- [Control].Location = New Point(x, y)
- End Sub
- Private Delegate Sub delegateOpacity(C As Form, f As Double)
- Private delegatoOpacità As New delegateOpacity(AddressOf Opacità)
- Private Sub Opacità(C As Form, f As Double)
- C.Opacity = f
- End Sub
- Private Delegate Sub delegatehide(c As Form)
- Private delegatohide As New delegatehide(AddressOf hide)
- Private Sub hide(c As Form)
- c.Hide()
- End Sub
- #End Region
- Private AnimationThread As Threading.Thread
- Private Sub MovimentoAnimation()
- FormBallon.Invoke(delegatoShow)
- For y As Integer = masterH To (masterH - FormBallon.Height) Step -(VelocitàMovimento / 10)
- FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, y)
- System.Threading.Thread.Sleep(VelocitàMovimento / 10)
- Next
- Threading.Thread.Sleep(ChiudiDopo)
- MovimentoChiusura()
- End Sub
- Private Sub MovimentoChiusura()
- For y As Integer = (masterH - FormBallon.Height) To masterH Step +(VelocitàMovimento / 10)
- FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, y)
- System.Threading.Thread.Sleep(VelocitàMovimento / 10)
- Next
- FormBallon.Invoke(delegatohide, FormBallon)
- End Sub
- Private Sub FadeChiusura()
- For opa As Double = 1 To 0 Step -0.01
- FormBallon.Invoke(delegatoOpacità, FormBallon, opa)
- Threading.Thread.Sleep(10)
- Next
- FormBallon.Invoke(delegatohide, FormBallon)
- End Sub
- Private Sub OpacitàAnimation()
- FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, masterH - FormBallon.Height)
- FormBallon.Invoke(delegatoShow)
- FormBallon.Invoke(delegatoOpacità, FormBallon, 0.0)
- For opa As Double = 0 To 1 Step 0.01
- FormBallon.Invoke(delegatoOpacità, FormBallon, opa)
- Threading.Thread.Sleep(10)
- Next
- Threading.Thread.Sleep(ChiudiDopo)
- FadeChiusura()
- End Sub
- #End Region
- Public Sub ShowBallon()
- Select Case Tipo
- Case ETipo.Movimento
- AnimationThread = New Threading.Thread(AddressOf MovimentoAnimation)
- If Not AnimationThread.IsAlive Then
- AnimationThread.Start()
- End If
- Case ETipo.Opacità
- AnimationThread = New Threading.Thread(AddressOf OpacitàAnimation)
- If Not AnimationThread.IsAlive Then
- AnimationThread.Start()
- End If
- End Select
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement