RazerX

PopUp Form Manager -VB- / v1.0.5

Dec 3rd, 2013
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 19.19 KB | None | 0 0
  1. Option Strict On
  2. Namespace PopUpMaster
  3.  
  4.     ''' <summary>
  5.     ''' A windows Form that you can use as template for you PopUps.
  6.     ''' </summary>
  7.     ''' <remarks></remarks>
  8.     Public Class PopUpWindowTemplate
  9.  
  10. #Region "        Designer"
  11.         Inherits System.Windows.Forms.Form
  12.  
  13.         'Form overrides dispose to clean up the component list.
  14.         <System.Diagnostics.DebuggerNonUserCode()> _
  15.         Protected Overrides Sub Dispose(ByVal disposing As Boolean)
  16.             Try
  17.                 If disposing AndAlso components IsNot Nothing Then
  18.                     components.Dispose()
  19.                 End If
  20.             Finally
  21.                 MyBase.Dispose(disposing)
  22.             End Try
  23.         End Sub
  24.  
  25.         'Required by the Windows Form Designer
  26.         Private components As System.ComponentModel.IContainer
  27.  
  28.         'NOTE: The following procedure is required by the Windows Form Designer
  29.         'It can be modified using the Windows Form Designer.  
  30.         'Do not modify it using the code editor.
  31.         <System.Diagnostics.DebuggerStepThrough()> _
  32.         Private Sub InitializeComponent()
  33.             Me.lblTitle = New System.Windows.Forms.Label()
  34.             Me.txbMessage = New System.Windows.Forms.TextBox()
  35.             Me.lblClose = New System.Windows.Forms.Label()
  36.             Me.SuspendLayout()
  37.             '
  38.             'lblTitle
  39.             '
  40.             Me.lblTitle.AutoSize = True
  41.             Me.lblTitle.Location = New System.Drawing.Point(5, 5)
  42.             Me.lblTitle.Name = "lblTitle"
  43.             Me.lblTitle.Size = New System.Drawing.Size(37, 21)
  44.             Me.lblTitle.TabIndex = 0
  45.             Me.lblTitle.Text = "Title"
  46.             '
  47.             'txbMessage
  48.             '
  49.             Me.txbMessage.BackColor = System.Drawing.Color.FromArgb(CType(CType(55, Byte), Integer), CType(CType(66, Byte), Integer), CType(CType(77, Byte), Integer))
  50.             Me.txbMessage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
  51.             Me.txbMessage.Cursor = System.Windows.Forms.Cursors.Arrow
  52.             Me.txbMessage.Enabled = False
  53.             Me.txbMessage.ForeColor = System.Drawing.Color.White
  54.             Me.txbMessage.HideSelection = False
  55.             Me.txbMessage.Location = New System.Drawing.Point(12, 33)
  56.             Me.txbMessage.Multiline = True
  57.             Me.txbMessage.Name = "txbMessage"
  58.             Me.txbMessage.ReadOnly = True
  59.             Me.txbMessage.Size = New System.Drawing.Size(276, 155)
  60.             Me.txbMessage.TabIndex = 1
  61.             '
  62.             'lblClose
  63.             '
  64.             Me.lblClose.AutoSize = True
  65.             Me.lblClose.Font = New System.Drawing.Font("Webdings", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
  66.             Me.lblClose.Location = New System.Drawing.Point(273, 5)
  67.             Me.lblClose.Name = "lblClose"
  68.             Me.lblClose.Size = New System.Drawing.Size(25, 19)
  69.             Me.lblClose.TabIndex = 2
  70.             Me.lblClose.Text = "r"
  71.             '
  72.             'PopUpWindowTemplate
  73.             '
  74.             Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 21.0!)
  75.             Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
  76.             Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(44, Byte), Integer), CType(CType(55, Byte), Integer), CType(CType(66, Byte), Integer))
  77.             Me.ClientSize = New System.Drawing.Size(300, 200)
  78.             Me.Controls.Add(Me.lblClose)
  79.             Me.Controls.Add(Me.txbMessage)
  80.             Me.Controls.Add(Me.lblTitle)
  81.             Me.Font = New System.Drawing.Font("Segoe UI Light", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  82.             Me.ForeColor = System.Drawing.Color.White
  83.             Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
  84.             Me.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5)
  85.             Me.MaximizeBox = False
  86.             Me.MinimizeBox = False
  87.             Me.Name = "PopUpWindowTemplate"
  88.             Me.ShowInTaskbar = False
  89.             Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
  90.             Me.Text = "PopUp"
  91.             Me.ResumeLayout(False)
  92.             Me.PerformLayout()
  93.  
  94.         End Sub
  95.         Friend WithEvents lblTitle As System.Windows.Forms.Label
  96.         Friend WithEvents txbMessage As System.Windows.Forms.TextBox
  97.         Friend WithEvents lblClose As System.Windows.Forms.Label
  98.  
  99. #End Region
  100.  
  101.         Property title As String
  102.             Set(ByVal value As String)
  103.                 lblTitle.Text = value
  104.             End Set
  105.             Get
  106.                 Return lblTitle.Text
  107.             End Get
  108.         End Property
  109.         Property message As String
  110.             Set(ByVal value As String)
  111.                 txbMessage.Text = value
  112.             End Set
  113.             Get
  114.                 Return txbMessage.Text
  115.             End Get
  116.         End Property
  117.  
  118.         Sub closePopUp() Handles lblClose.Click
  119.             Me.Close()
  120.         End Sub
  121.  
  122.         Sub New(ByVal Title As String, ByVal Message As String, Optional ByVal ShowClose As Boolean = True)
  123.             InitializeComponent()
  124.             lblTitle.Text = Title
  125.             txbMessage.Text = Message
  126.             If ShowClose = False Then lblClose.Visible = False
  127.  
  128.         End Sub
  129.  
  130.     End Class
  131.  
  132.     ''' <summary>
  133.     ''' Advanced WindowsPopUp Manager
  134.     '''
  135.     ''' With this beauty you can transform every form in your project into a popup window.
  136.     '''
  137.     ''' coded by .RazerX
  138.     ''' The Project is an advanced "Copy" of this: http://www.hackforums.net/showthread.php?tid=3901121
  139.     '''
  140.     ''' Nothing is copied from the original project, everything is coded from the begining.
  141.     ''' </summary>
  142.     ''' <remarks></remarks>
  143.     Public Class AdvancedPopUpManager
  144.  
  145.         Private _PopupsPending As New List(Of PopUpWindow) 'The list that will contain all the popups that we are going to show.
  146.         Private _ScreenWidth As Integer = My.Computer.Screen.WorkingArea.Width 'Variable that will contain the screen width
  147.         Private _ScreenHeight As Integer = My.Computer.Screen.WorkingArea.Height 'The same with the above but for the height.
  148.         Private _CurrentWindow As PopUpWindow 'This variable will change into the window that is being showed at that moment.
  149.         Private WithEvents tmrAnimator As New Timer With {.Interval = 10}
  150.         Private secondsPassed As Integer = 0 'A variable that will check for the seconds that has passed
  151.         Private stepType As Integer = 0 'An easy way to handle the different events in timers ticks.
  152.         Private locationEnd As Point 'The location where the window is fully shown, Defined in the ShowPopUpWindow sub.
  153.         Private popUpShowing As Boolean = False 'A variable that will check if there is a popup window being shown.
  154.         Public Event Window_Closed()
  155.         ''' <summary>
  156.         ''' With this sub you can directly show a popup window.
  157.         ''' </summary>
  158.         ''' <param name="Window">Define which window(Form) you want to show</param>
  159.         ''' <remarks></remarks>
  160.         Sub ShowPopUp(ByRef Window As PopUpWindow)
  161.  
  162.             If popUpShowing = True Then AddNewPop(Window) : Exit Sub ' If there is a window already been shown, add the new window to pendings.
  163.             _CurrentWindow = Window 'Simple.
  164.  
  165.             'Here we position our popup form in the selected location.
  166.             'we also add  the position where the form is fully shown using the LocationEnd variable.
  167.             Select Case Window.startLocation
  168.                 Case PopUpWindow.StartLocationEnum.DownLeft
  169.                     _CurrentWindow.popUpWindow.Location = New Point(0, _ScreenHeight + _CurrentWindow.popUpWindow.Height)
  170.                     locationEnd = New Point(0, _ScreenHeight - _CurrentWindow.popUpWindow.Height)
  171.                 Case PopUpWindow.StartLocationEnum.DownRight
  172.                     _CurrentWindow.popUpWindow.Location = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, _ScreenHeight + _CurrentWindow.popUpWindow.Height)
  173.                     locationEnd = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, _ScreenHeight - _CurrentWindow.popUpWindow.Height)
  174.                 Case PopUpWindow.StartLocationEnum.UpLeft
  175.                     _CurrentWindow.popUpWindow.Location = New Point(0, 0 - _CurrentWindow.popUpWindow.Height)
  176.                     locationEnd = New Point(0, 0)
  177.                 Case PopUpWindow.StartLocationEnum.UpRight
  178.                     _CurrentWindow.popUpWindow.Location = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, 0 - _CurrentWindow.popUpWindow.Height)
  179.                     locationEnd = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, 0)
  180.                 Case PopUpWindow.StartLocationEnum.Center
  181.                     'If the stat point is Center, only fadein_fadeout can  be
  182.                     locationEnd = New Point(CInt((_ScreenWidth / 2) - (_CurrentWindow.popUpWindow.Width / 2)), CInt((_ScreenHeight / 2) - (_CurrentWindow.popUpWindow.Height / 2)))
  183.                     _CurrentWindow.type = PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut
  184.             End Select
  185.  
  186.             'If the start Type is fadein we make our opacity to 0 and make our position to fully shown.
  187.             If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.Fadein_WalkOut) Then
  188.                 _CurrentWindow.popUpWindow.Opacity = 0
  189.                 _CurrentWindow.popUpWindow.Location = locationEnd
  190.             End If
  191.  
  192.             _CurrentWindow.popUpWindow.Show() 'Show the window on screen
  193.             'We start the timer and make the timer variables to 0
  194.             tmrAnimator.Start()
  195.             stepType = 0
  196.             secondsPassed = 0
  197.         End Sub
  198.  
  199.         ''' <summary>
  200.         ''' Shows the next popup window into the pending list.
  201.         ''' </summary>
  202.         ''' <remarks></remarks>
  203.         Sub ShowNextPopUP()
  204.             ShowPopUp(_PopupsPending(0)) 'i use the 0 index because every time a popup window is finished it get's deleten from
  205.             'the pending list, thus the next popup will take it's place, so it will allways be a index 0l
  206.         End Sub
  207.  
  208.         ''' <summary>
  209.         ''' Delete all current pending popup windows.If there is a popup already being showed,it will not be stopped.
  210.         ''' </summary>
  211.         ''' <remarks></remarks>
  212.         Sub ClearPendingPopUps()
  213.             _PopupsPending.Clear()
  214.         End Sub
  215.  
  216.         ''' <summary>
  217.         ''' Add a new popup window to the pending list
  218.         ''' </summary>
  219.         ''' <remarks></remarks>
  220.         Sub AddNewPop(ByRef Window As PopUpWindow)
  221.             _PopupsPending.Add(Window)
  222.         End Sub
  223.  
  224.         Private Sub tmrAnimator_Tick() Handles tmrAnimator.Tick
  225.  
  226.             popUpShowing = True ' we are showing a window so we change the variable to true
  227.  
  228.             '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229.             'Step 0
  230.             ' the step  were we show the popup window.
  231.  
  232.             If stepType = 0 Then
  233.                 'If the start type is fadein we change the opacity until it reaches 1
  234.                 If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.Fadein_WalkOut) Then
  235.                     If _CurrentWindow.popUpWindow.Opacity < 1 Then
  236.                         _CurrentWindow.popUpWindow.Opacity += _CurrentWindow.FadeSpeed
  237.                     Else 'If Opacity = 1 then ,go to step 1
  238.                         stepType = 1
  239.                     End If
  240.                 Else 'If the start type is WalkIn then move the form into the locationEnd point.
  241.                     If _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpRight) Or _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpLeft) Then
  242.                         If _CurrentWindow.popUpWindow.Location.Y < locationEnd.Y Then
  243.                             _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.MoveSpeed)
  244.                         Else
  245.                             stepType = 1
  246.                         End If
  247.                     Else
  248.                         If _CurrentWindow.popUpWindow.Location.Y > locationEnd.Y Then
  249.                             _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y - _CurrentWindow.MoveSpeed)
  250.                         Else
  251.                             stepType = 1
  252.                         End If
  253.                     End If
  254.                 End If
  255.  
  256.                 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  257.                 'Step 1
  258.                 'I this step the window is fully shown, so we wait until the seconds you defined have passed.
  259.  
  260.             ElseIf stepType = 1 Then
  261.                 If secondsPassed < (_CurrentWindow.secondsVisible * 1000) Then 'Timers works in miliseconds so we multiply the
  262.                     'defined seconds * 1000
  263.                     secondsPassed += 20
  264.                 Else
  265.                     stepType = 2 'if the seconds passed are equal the seconds that you defined, goto step 2
  266.                 End If
  267.  
  268.                 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  269.                 'Step 2
  270.                 'In this step the form goes from shown to closed
  271.  
  272.             ElseIf stepType = 2 Then
  273.  
  274.                 'we do the same thing as in step 0 but we inverse the actions, so the form closes it's self.
  275.                 If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.WalkIn_Fadeout) Then
  276.                     If _CurrentWindow.popUpWindow.Opacity > 0 Then
  277.                         _CurrentWindow.popUpWindow.Opacity -= _CurrentWindow.FadeSpeed
  278.                     Else
  279.                         stepType = 3
  280.                         _CurrentWindow.popUpWindow.Close()
  281.                     End If
  282.                 Else
  283.                     If _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpRight) Or _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpLeft) Then
  284.                         If (_CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.popUpWindow.Height) >= locationEnd.Y Then
  285.                             _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y - _CurrentWindow.MoveSpeed)
  286.                         Else
  287.                             stepType = 3
  288.                             _CurrentWindow.popUpWindow.Close()
  289.                         End If
  290.                     Else
  291.                         If _CurrentWindow.popUpWindow.Location.Y <= (locationEnd.Y + _CurrentWindow.popUpWindow.Height) Then
  292.                             _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.MoveSpeed)
  293.                         Else
  294.                             stepType = 3
  295.                             _CurrentWindow.popUpWindow.Close()
  296.                         End If
  297.                     End If
  298.                 End If
  299.  
  300.                 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  301.                 'Step 3
  302.  
  303.             ElseIf stepType = 3 Then
  304.                 _PopupsPending.Remove(_CurrentWindow) 'The popup window is shown so let's delete it from the pending list.
  305.                 tmrAnimator.Stop() 'stop the timer.
  306.                 popUpShowing = False 'there is no window being shown so we change the variable to false
  307.                 RaiseEvent Window_Closed() 'here there is an event raised to inform the user that the popup was closed
  308.                 If _PopupsPending.Count <> 0 Then ' if there are more items in the pending list we add a new window.
  309.                     ShowNextPopUP() 'show the next window
  310.                 End If
  311.             End If
  312.         End Sub
  313.         ''' <summary>
  314.         ''' A class that will handle the properties of a popup window.
  315.         ''' </summary>
  316.         ''' <remarks></remarks>
  317.         Class PopUpWindow
  318. #Region "Enums"
  319.             ''' <summary>
  320.             ''' Defines the location where the PopUp form is going to be loaded.
  321.             ''' </summary>
  322.             ''' <remarks></remarks>
  323.             Enum StartLocationEnum
  324.                 UpRight
  325.                 UpLeft
  326.                 DownRight
  327.                 DownLeft
  328.                 Center
  329.             End Enum
  330.             ''' <summary>
  331.             ''' Define the PopUp Type.
  332.             ''' </summary>
  333.             ''' <remarks></remarks>
  334.             Enum PopUpTypeEnum
  335.                 FadeIn_FadeOut
  336.                 Fadein_WalkOut
  337.                 WalkIn_Fadeout
  338.                 WalkIn_WalkOut
  339.             End Enum
  340. #End Region
  341. #Region "Properties"
  342.             Private _type As PopUpTypeEnum = PopUpTypeEnum.WalkIn_WalkOut
  343.             Property type As PopUpTypeEnum
  344.                 Set(ByVal value As PopUpTypeEnum)
  345.                     _type = value
  346.                 End Set
  347.                 Get
  348.                     Return _type
  349.                 End Get
  350.             End Property
  351.             Private _startLocation As StartLocationEnum = StartLocationEnum.DownRight
  352.             Property startLocation As StartLocationEnum
  353.                 Set(ByVal value As StartLocationEnum)
  354.                     _startLocation = value
  355.                 End Set
  356.                 Get
  357.                     Return _startLocation
  358.                 End Get
  359.             End Property
  360.             Private _secondsVisible As Integer = 4
  361.             Property secondsVisible As Integer
  362.                 Set(ByVal value As Integer)
  363.                     _secondsVisible = value
  364.                 End Set
  365.                 Get
  366.                     Return _secondsVisible
  367.                 End Get
  368.             End Property
  369.             Private _popUpWindow As Form = New PopUpWindowTemplate("Test", "Test", False)
  370.             Property popUpWindow As Form
  371.                 Set(ByVal value As Form)
  372.                     _popUpWindow = value
  373.                 End Set
  374.                 Get
  375.                     Return _popUpWindow
  376.                 End Get
  377.             End Property
  378.             Private _fadeSpeed As Double = 0.02
  379.             Property FadeSpeed As Double
  380.                 Set(ByVal value As Double)
  381.                     _fadeSpeed = value
  382.                 End Set
  383.                 Get
  384.                     Return _fadeSpeed
  385.                 End Get
  386.             End Property
  387.             Private _moveSpeed As Integer = 1
  388.             Property MoveSpeed As Integer
  389.                 Set(ByVal value As Integer)
  390.                     _moveSpeed = value
  391.                 End Set
  392.                 Get
  393.                     Return _moveSpeed
  394.                 End Get
  395.             End Property
  396. #End Region
  397.             Sub New(ByRef Window As Form)
  398.                 popUpWindow = Window
  399.             End Sub
  400.         End Class
  401.     End Class
  402. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment