Advertisement
Guest User

mybaloon

a guest
Apr 16th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.88 KB | None | 0 0
  1. '# created by tuttomax
  2. Public Class MyBaloon : Inherits System.ComponentModel.Component
  3.     Private masterH As Integer = My.Computer.Screen.WorkingArea.Height
  4.     Private masterW As Integer = My.Computer.Screen.WorkingArea.Width
  5.  
  6. #Region "Inizializzo oggetti"
  7.     Sub New()
  8.         CreateFormBallonStandard()
  9.     End Sub
  10.  
  11. #Region "FormBallon"
  12.     Private WithEvents FormBallon As New Form
  13. #Region "Propietà"
  14.     Private _Width As Integer = 250
  15.     Public Property Width As Integer
  16.         Get
  17.             Return _Width
  18.         End Get
  19.         Set(value As Integer)
  20.             _Width = value
  21.             FormBallon.Width = _Width
  22.         End Set
  23.     End Property
  24.  
  25.     Private _Height As Integer = 50
  26.     Public Property Height As Integer
  27.         Get
  28.             Return _Height
  29.         End Get
  30.         Set(value As Integer)
  31.             _Height = value
  32.             FormBallon.Height = _Height
  33.         End Set
  34.     End Property
  35.  
  36.     Private _Image As Image
  37.     Public Property Image As Image
  38.         Get
  39.             Return _Image
  40.         End Get
  41.         Set(value As Image)
  42.             _Image = value
  43.         End Set
  44.     End Property
  45.  
  46.     Enum ETipo
  47.         Movimento
  48.         Opacità
  49.     End Enum
  50.     Private _Tipo As ETipo = ETipo.Movimento
  51.     Public Property Tipo As ETipo
  52.         Get
  53.             Return _Tipo
  54.         End Get
  55.         Set(value As ETipo)
  56.             _Tipo = value
  57.         End Set
  58.     End Property
  59.  
  60.     Private _Velocità As Integer = 10
  61.     Public Property VelocitàMovimento As Integer
  62.         Get
  63.             Return _Velocità
  64.         End Get
  65.         Set(value As Integer)
  66.             _Velocità = value
  67.         End Set
  68.     End Property
  69.  
  70.     Private _ChiudiDopo As Integer = 1000
  71.     Public Property ChiudiDopo As Integer
  72.         Get
  73.             Return _ChiudiDopo
  74.         End Get
  75.         Set(value As Integer)
  76.             _ChiudiDopo = value
  77.         End Set
  78.     End Property
  79. #End Region
  80.  
  81.     Private Sub CreateFormBallonStandard()
  82.         With FormBallon
  83.             .Width = Width
  84.             .Height = Height
  85.             .FormBorderStyle = FormBorderStyle.None
  86.             .Location = New Point(masterW - FormBallon.Width, masterH)
  87.             .Show()
  88.             .Hide()
  89.         End With
  90.     End Sub
  91.  
  92.  
  93.     Private Sub OnPaintBallonForm(ByVal sender As Object, e As PaintEventArgs) Handles FormBallon.Paint
  94.         Dim W As Integer = FormBallon.Width
  95.         Dim H As Integer = FormBallon.Height
  96.         'QUI VA CAMBIATA LA GRAFICA
  97.  
  98.         Dim masterRectangle As New Rectangle(0, 0, W, H)
  99.         e.Graphics.FillRectangle(Brushes.Red, masterRectangle)
  100.  
  101.         If Not Image Is Nothing Then Dim NewImage As New Bitmap(Image, 36, 36) : e.Graphics.DrawImage(NewImage, 5, 10)
  102.  
  103.  
  104.     End Sub
  105. #End Region
  106.  
  107. #End Region
  108.  
  109. #Region "Animazione"
  110. #Region "Delegati"
  111.     Private Delegate Sub delegateShow()
  112.     Private delegatoShow As New delegateShow(AddressOf Show)
  113.     Private Sub Show()
  114.         FormBallon.Show()
  115.     End Sub
  116.  
  117.     Private Delegate Sub delegateLocation(c As Control, x As Integer, y As Integer)
  118.     Private delegatoLocation As New delegateLocation(AddressOf Location)
  119.     Private Sub Location([Control] As Control, x As Integer, y As Integer)
  120.         [Control].Location = New Point(x, y)
  121.     End Sub
  122.  
  123.     Private Delegate Sub delegateOpacity(C As Form, f As Double)
  124.     Private delegatoOpacità As New delegateOpacity(AddressOf Opacità)
  125.     Private Sub Opacità(C As Form, f As Double)
  126.         C.Opacity = f
  127.     End Sub
  128.  
  129.     Private Delegate Sub delegatehide(c As Form)
  130.     Private delegatohide As New delegatehide(AddressOf hide)
  131.     Private Sub hide(c As Form)
  132.         c.Hide()
  133.     End Sub
  134.  
  135. #End Region
  136.  
  137.     Private AnimationThread As Threading.Thread
  138.     Private Sub MovimentoAnimation()
  139.         FormBallon.Invoke(delegatoShow)
  140.         For y As Integer = masterH To (masterH - FormBallon.Height) Step -(VelocitàMovimento / 10)
  141.             FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, y)
  142.             System.Threading.Thread.Sleep(VelocitàMovimento / 10)
  143.         Next
  144.         Threading.Thread.Sleep(ChiudiDopo)
  145.         MovimentoChiusura()
  146.  
  147.    End Sub
  148.     Private Sub MovimentoChiusura()
  149.         For y As Integer = (masterH - FormBallon.Height) To masterH Step +(VelocitàMovimento / 10)
  150.             FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, y)
  151.             System.Threading.Thread.Sleep(VelocitàMovimento / 10)
  152.         Next
  153.         FormBallon.Invoke(delegatohide, FormBallon)
  154.  
  155.     End Sub
  156.  
  157.     Private Sub FadeChiusura()
  158.         For opa As Double = 1 To 0 Step -0.01
  159.             FormBallon.Invoke(delegatoOpacità, FormBallon, opa)
  160.             Threading.Thread.Sleep(10)
  161.         Next
  162.         FormBallon.Invoke(delegatohide, FormBallon)
  163.     End Sub
  164.     Private Sub OpacitàAnimation()
  165.         FormBallon.Invoke(delegatoLocation, FormBallon, masterW - FormBallon.Width, masterH - FormBallon.Height)
  166.         FormBallon.Invoke(delegatoShow)
  167.         FormBallon.Invoke(delegatoOpacità, FormBallon, 0.0)
  168.  
  169.         For opa As Double = 0 To 1 Step 0.01
  170.             FormBallon.Invoke(delegatoOpacità, FormBallon, opa)
  171.             Threading.Thread.Sleep(10)
  172.         Next
  173.         Threading.Thread.Sleep(ChiudiDopo)
  174.         FadeChiusura()
  175.  
  176.  
  177.  
  178.     End Sub
  179.  
  180. #End Region
  181.  
  182.  
  183.  
  184.  
  185.     Public Sub ShowBallon()
  186.         Select Case Tipo
  187.             Case ETipo.Movimento
  188.                 AnimationThread = New Threading.Thread(AddressOf MovimentoAnimation)
  189.                 If Not AnimationThread.IsAlive Then
  190.                     AnimationThread.Start()
  191.                 End If
  192.             Case ETipo.Opacità
  193.                 AnimationThread = New Threading.Thread(AddressOf OpacitàAnimation)
  194.                 If Not AnimationThread.IsAlive Then
  195.                     AnimationThread.Start()
  196.                 End If
  197.         End Select
  198.  
  199.     End Sub
  200.  
  201.  
  202. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement