simple question, many forms

tesseract

Member
Joined
Jul 3, 2008
Messages
13
Programming Experience
3-5
what i want to do is make a notification system, kind of like aim were a new little box will show up to alert the user of a couple different things.

this is how far i have gotten :

VB.NET:
Dim popups As ArrayList

    Public Sub newEvent(ByVal title As String, ByVal description As String)
        popups.Add(New Form())
        lastPopup.setText(title, description)
        lastPopup.Left = 1440 - lastPopup.Width
        lastPopup.Top = 900 - lastPopup.Height
        lastPopup.Visible = True
    End Sub

    Public Function lastPopup() As Events
        Return popups.Item(popups.Count - 1)
    End Function

I use an arraylist because i dont know how many messages will come around the same time, but i could switch to an array if i must.

this is the form that i made as kind of a template :

VB.NET:
Public Class Events

    Public Sub setText(ByVal t As String, ByVal d As String)
        title.Text = t
        Description.Text = d
    End Sub

End Class

its just got a couple text boxes for now

how can i make these new forms every time i have a new message to display and the clean up after them when they are done.
 
Something along the lines of this :

VB.NET:
Addhandler lastPopup.Disposed, addressof lastPopup_Disposed

then you would have a method like this :

VB.NET:
private sub lastPopup_Disposed(sender as Object, args as EventArgs)
    popups.remove(DirectCast(sender, Form))
end sub

You should also consider making the popups ArrayList a List(Of Form) instead so it type safe. It may break some of your method calls that didn't care about type when it called methods on the list, but a few casts will do the trick. Search "generic collections" for more information.

Also, you can use lastPopup.Show() instead of lastPopup.Visible = true.

You could also use lastPopup.ShowDialog() to make it stick over your may form and block until the the dialog is closed. That way, you don't even need to keep a list of dialogs. You can react to the form's closing by adding code after the ShowDialog() call.
 
Back
Top