Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Strict On
- Namespace PopUpMaster
- ''' <summary>
- ''' A windows Form that you can use as template for you PopUps.
- ''' </summary>
- ''' <remarks></remarks>
- Public Class PopUpWindowTemplate
- #Region " Designer"
- Inherits System.Windows.Forms.Form
- 'Form overrides dispose to clean up the component list.
- <System.Diagnostics.DebuggerNonUserCode()> _
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- Try
- If disposing AndAlso components IsNot Nothing Then
- components.Dispose()
- End If
- Finally
- MyBase.Dispose(disposing)
- End Try
- End Sub
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.IContainer
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> _
- Private Sub InitializeComponent()
- Me.lblTitle = New System.Windows.Forms.Label()
- Me.txbMessage = New System.Windows.Forms.TextBox()
- Me.lblClose = New System.Windows.Forms.Label()
- Me.SuspendLayout()
- '
- 'lblTitle
- '
- Me.lblTitle.AutoSize = True
- Me.lblTitle.Location = New System.Drawing.Point(5, 5)
- Me.lblTitle.Name = "lblTitle"
- Me.lblTitle.Size = New System.Drawing.Size(37, 21)
- Me.lblTitle.TabIndex = 0
- Me.lblTitle.Text = "Title"
- '
- 'txbMessage
- '
- Me.txbMessage.BackColor = System.Drawing.Color.FromArgb(CType(CType(55, Byte), Integer), CType(CType(66, Byte), Integer), CType(CType(77, Byte), Integer))
- Me.txbMessage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
- Me.txbMessage.Cursor = System.Windows.Forms.Cursors.Arrow
- Me.txbMessage.Enabled = False
- Me.txbMessage.ForeColor = System.Drawing.Color.White
- Me.txbMessage.HideSelection = False
- Me.txbMessage.Location = New System.Drawing.Point(12, 33)
- Me.txbMessage.Multiline = True
- Me.txbMessage.Name = "txbMessage"
- Me.txbMessage.ReadOnly = True
- Me.txbMessage.Size = New System.Drawing.Size(276, 155)
- Me.txbMessage.TabIndex = 1
- '
- 'lblClose
- '
- Me.lblClose.AutoSize = True
- Me.lblClose.Font = New System.Drawing.Font("Webdings", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
- Me.lblClose.Location = New System.Drawing.Point(273, 5)
- Me.lblClose.Name = "lblClose"
- Me.lblClose.Size = New System.Drawing.Size(25, 19)
- Me.lblClose.TabIndex = 2
- Me.lblClose.Text = "r"
- '
- 'PopUpWindowTemplate
- '
- Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 21.0!)
- Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
- Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(44, Byte), Integer), CType(CType(55, Byte), Integer), CType(CType(66, Byte), Integer))
- Me.ClientSize = New System.Drawing.Size(300, 200)
- Me.Controls.Add(Me.lblClose)
- Me.Controls.Add(Me.txbMessage)
- Me.Controls.Add(Me.lblTitle)
- Me.Font = New System.Drawing.Font("Segoe UI Light", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.ForeColor = System.Drawing.Color.White
- Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
- Me.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5)
- Me.MaximizeBox = False
- Me.MinimizeBox = False
- Me.Name = "PopUpWindowTemplate"
- Me.ShowInTaskbar = False
- Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
- Me.Text = "PopUp"
- Me.ResumeLayout(False)
- Me.PerformLayout()
- End Sub
- Friend WithEvents lblTitle As System.Windows.Forms.Label
- Friend WithEvents txbMessage As System.Windows.Forms.TextBox
- Friend WithEvents lblClose As System.Windows.Forms.Label
- #End Region
- Property title As String
- Set(ByVal value As String)
- lblTitle.Text = value
- End Set
- Get
- Return lblTitle.Text
- End Get
- End Property
- Property message As String
- Set(ByVal value As String)
- txbMessage.Text = value
- End Set
- Get
- Return txbMessage.Text
- End Get
- End Property
- Sub closePopUp() Handles lblClose.Click
- Me.Close()
- End Sub
- Sub New(ByVal Title As String, ByVal Message As String, Optional ByVal ShowClose As Boolean = True)
- InitializeComponent()
- lblTitle.Text = Title
- txbMessage.Text = Message
- If ShowClose = False Then lblClose.Visible = False
- End Sub
- End Class
- ''' <summary>
- ''' Advanced WindowsPopUp Manager
- '''
- ''' With this beauty you can transform every form in your project into a popup window.
- '''
- ''' coded by .RazerX
- ''' The Project is an advanced "Copy" of this: http://www.hackforums.net/showthread.php?tid=3901121
- '''
- ''' Nothing is copied from the original project, everything is coded from the begining.
- ''' </summary>
- ''' <remarks></remarks>
- Public Class AdvancedPopUpManager
- Private _PopupsPending As New List(Of PopUpWindow) 'The list that will contain all the popups that we are going to show.
- Private _ScreenWidth As Integer = My.Computer.Screen.WorkingArea.Width 'Variable that will contain the screen width
- Private _ScreenHeight As Integer = My.Computer.Screen.WorkingArea.Height 'The same with the above but for the height.
- Private _CurrentWindow As PopUpWindow 'This variable will change into the window that is being showed at that moment.
- Private WithEvents tmrAnimator As New Timer With {.Interval = 10}
- Private secondsPassed As Integer = 0 'A variable that will check for the seconds that has passed
- Private stepType As Integer = 0 'An easy way to handle the different events in timers ticks.
- Private locationEnd As Point 'The location where the window is fully shown, Defined in the ShowPopUpWindow sub.
- Private popUpShowing As Boolean = False 'A variable that will check if there is a popup window being shown.
- Public Event Window_Closed()
- ''' <summary>
- ''' With this sub you can directly show a popup window.
- ''' </summary>
- ''' <param name="Window">Define which window(Form) you want to show</param>
- ''' <remarks></remarks>
- Sub ShowPopUp(ByRef Window As PopUpWindow)
- If popUpShowing = True Then AddNewPop(Window) : Exit Sub ' If there is a window already been shown, add the new window to pendings.
- _CurrentWindow = Window 'Simple.
- 'Here we position our popup form in the selected location.
- 'we also add the position where the form is fully shown using the LocationEnd variable.
- Select Case Window.startLocation
- Case PopUpWindow.StartLocationEnum.DownLeft
- _CurrentWindow.popUpWindow.Location = New Point(0, _ScreenHeight + _CurrentWindow.popUpWindow.Height)
- locationEnd = New Point(0, _ScreenHeight - _CurrentWindow.popUpWindow.Height)
- Case PopUpWindow.StartLocationEnum.DownRight
- _CurrentWindow.popUpWindow.Location = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, _ScreenHeight + _CurrentWindow.popUpWindow.Height)
- locationEnd = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, _ScreenHeight - _CurrentWindow.popUpWindow.Height)
- Case PopUpWindow.StartLocationEnum.UpLeft
- _CurrentWindow.popUpWindow.Location = New Point(0, 0 - _CurrentWindow.popUpWindow.Height)
- locationEnd = New Point(0, 0)
- Case PopUpWindow.StartLocationEnum.UpRight
- _CurrentWindow.popUpWindow.Location = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, 0 - _CurrentWindow.popUpWindow.Height)
- locationEnd = New Point(_ScreenWidth - _CurrentWindow.popUpWindow.Width, 0)
- Case PopUpWindow.StartLocationEnum.Center
- 'If the stat point is Center, only fadein_fadeout can be
- locationEnd = New Point(CInt((_ScreenWidth / 2) - (_CurrentWindow.popUpWindow.Width / 2)), CInt((_ScreenHeight / 2) - (_CurrentWindow.popUpWindow.Height / 2)))
- _CurrentWindow.type = PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut
- End Select
- 'If the start Type is fadein we make our opacity to 0 and make our position to fully shown.
- If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.Fadein_WalkOut) Then
- _CurrentWindow.popUpWindow.Opacity = 0
- _CurrentWindow.popUpWindow.Location = locationEnd
- End If
- _CurrentWindow.popUpWindow.Show() 'Show the window on screen
- 'We start the timer and make the timer variables to 0
- tmrAnimator.Start()
- stepType = 0
- secondsPassed = 0
- End Sub
- ''' <summary>
- ''' Shows the next popup window into the pending list.
- ''' </summary>
- ''' <remarks></remarks>
- Sub ShowNextPopUP()
- ShowPopUp(_PopupsPending(0)) 'i use the 0 index because every time a popup window is finished it get's deleten from
- 'the pending list, thus the next popup will take it's place, so it will allways be a index 0l
- End Sub
- ''' <summary>
- ''' Delete all current pending popup windows.If there is a popup already being showed,it will not be stopped.
- ''' </summary>
- ''' <remarks></remarks>
- Sub ClearPendingPopUps()
- _PopupsPending.Clear()
- End Sub
- ''' <summary>
- ''' Add a new popup window to the pending list
- ''' </summary>
- ''' <remarks></remarks>
- Sub AddNewPop(ByRef Window As PopUpWindow)
- _PopupsPending.Add(Window)
- End Sub
- Private Sub tmrAnimator_Tick() Handles tmrAnimator.Tick
- popUpShowing = True ' we are showing a window so we change the variable to true
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Step 0
- ' the step were we show the popup window.
- If stepType = 0 Then
- 'If the start type is fadein we change the opacity until it reaches 1
- If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.Fadein_WalkOut) Then
- If _CurrentWindow.popUpWindow.Opacity < 1 Then
- _CurrentWindow.popUpWindow.Opacity += _CurrentWindow.FadeSpeed
- Else 'If Opacity = 1 then ,go to step 1
- stepType = 1
- End If
- Else 'If the start type is WalkIn then move the form into the locationEnd point.
- If _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpRight) Or _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpLeft) Then
- If _CurrentWindow.popUpWindow.Location.Y < locationEnd.Y Then
- _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.MoveSpeed)
- Else
- stepType = 1
- End If
- Else
- If _CurrentWindow.popUpWindow.Location.Y > locationEnd.Y Then
- _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y - _CurrentWindow.MoveSpeed)
- Else
- stepType = 1
- End If
- End If
- End If
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Step 1
- 'I this step the window is fully shown, so we wait until the seconds you defined have passed.
- ElseIf stepType = 1 Then
- If secondsPassed < (_CurrentWindow.secondsVisible * 1000) Then 'Timers works in miliseconds so we multiply the
- 'defined seconds * 1000
- secondsPassed += 20
- Else
- stepType = 2 'if the seconds passed are equal the seconds that you defined, goto step 2
- End If
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Step 2
- 'In this step the form goes from shown to closed
- ElseIf stepType = 2 Then
- 'we do the same thing as in step 0 but we inverse the actions, so the form closes it's self.
- If _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut) Or _CurrentWindow.type = (PopUpWindow.PopUpTypeEnum.WalkIn_Fadeout) Then
- If _CurrentWindow.popUpWindow.Opacity > 0 Then
- _CurrentWindow.popUpWindow.Opacity -= _CurrentWindow.FadeSpeed
- Else
- stepType = 3
- _CurrentWindow.popUpWindow.Close()
- End If
- Else
- If _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpRight) Or _CurrentWindow.startLocation = (PopUpWindow.StartLocationEnum.UpLeft) Then
- If (_CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.popUpWindow.Height) >= locationEnd.Y Then
- _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y - _CurrentWindow.MoveSpeed)
- Else
- stepType = 3
- _CurrentWindow.popUpWindow.Close()
- End If
- Else
- If _CurrentWindow.popUpWindow.Location.Y <= (locationEnd.Y + _CurrentWindow.popUpWindow.Height) Then
- _CurrentWindow.popUpWindow.Location = New Point(_CurrentWindow.popUpWindow.Location.X, _CurrentWindow.popUpWindow.Location.Y + _CurrentWindow.MoveSpeed)
- Else
- stepType = 3
- _CurrentWindow.popUpWindow.Close()
- End If
- End If
- End If
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Step 3
- ElseIf stepType = 3 Then
- _PopupsPending.Remove(_CurrentWindow) 'The popup window is shown so let's delete it from the pending list.
- tmrAnimator.Stop() 'stop the timer.
- popUpShowing = False 'there is no window being shown so we change the variable to false
- RaiseEvent Window_Closed() 'here there is an event raised to inform the user that the popup was closed
- If _PopupsPending.Count <> 0 Then ' if there are more items in the pending list we add a new window.
- ShowNextPopUP() 'show the next window
- End If
- End If
- End Sub
- ''' <summary>
- ''' A class that will handle the properties of a popup window.
- ''' </summary>
- ''' <remarks></remarks>
- Class PopUpWindow
- #Region "Enums"
- ''' <summary>
- ''' Defines the location where the PopUp form is going to be loaded.
- ''' </summary>
- ''' <remarks></remarks>
- Enum StartLocationEnum
- UpRight
- UpLeft
- DownRight
- DownLeft
- Center
- End Enum
- ''' <summary>
- ''' Define the PopUp Type.
- ''' </summary>
- ''' <remarks></remarks>
- Enum PopUpTypeEnum
- FadeIn_FadeOut
- Fadein_WalkOut
- WalkIn_Fadeout
- WalkIn_WalkOut
- End Enum
- #End Region
- #Region "Properties"
- Private _type As PopUpTypeEnum = PopUpTypeEnum.WalkIn_WalkOut
- Property type As PopUpTypeEnum
- Set(ByVal value As PopUpTypeEnum)
- _type = value
- End Set
- Get
- Return _type
- End Get
- End Property
- Private _startLocation As StartLocationEnum = StartLocationEnum.DownRight
- Property startLocation As StartLocationEnum
- Set(ByVal value As StartLocationEnum)
- _startLocation = value
- End Set
- Get
- Return _startLocation
- End Get
- End Property
- Private _secondsVisible As Integer = 4
- Property secondsVisible As Integer
- Set(ByVal value As Integer)
- _secondsVisible = value
- End Set
- Get
- Return _secondsVisible
- End Get
- End Property
- Private _popUpWindow As Form = New PopUpWindowTemplate("Test", "Test", False)
- Property popUpWindow As Form
- Set(ByVal value As Form)
- _popUpWindow = value
- End Set
- Get
- Return _popUpWindow
- End Get
- End Property
- Private _fadeSpeed As Double = 0.02
- Property FadeSpeed As Double
- Set(ByVal value As Double)
- _fadeSpeed = value
- End Set
- Get
- Return _fadeSpeed
- End Get
- End Property
- Private _moveSpeed As Integer = 1
- Property MoveSpeed As Integer
- Set(ByVal value As Integer)
- _moveSpeed = value
- End Set
- Get
- Return _moveSpeed
- End Get
- End Property
- #End Region
- Sub New(ByRef Window As Form)
- popUpWindow = Window
- End Sub
- End Class
- End Class
- End Namespace
Advertisement
Add Comment
Please, Sign In to add comment