• 0

[VB.net] Show PowerPack Notify Window without form


Question

I have a class that I want to show the VB PowerPack Notification Window from, but the class doesn't have a form. I just want to show the window as it is running down its code. I saw a similar thread in another forum (the page on GotDotNet for the VB PowerPack) talking about the use of Delegates/Invoke. The code sample was in C++, so I tried to convert it to a VB.net equivalent. But, I can't get it to work. Here is what I have:

Public Class MyClass 
  Private NotificationWindow1 As VbPowerPack.NotificationWindow = New VbPowerPack.NotificationWindow 
  Private Delegate Sub DisplayNotification(ByVal strMessage As String) 
  Private Sub DisplayNotificationWindow(ByVal strMessage As String) 
    NotificationWindow1.Notify(strMessage, 3000) 
  End Sub 

   Public Sub MySubroutine 
     Dim NotificationWindow As DisplayNotification = AddressOf DisplayNotificationWindow 
     NotificationWindow.Invoke("My Message") 
   End Sub 
End Class

Can anyone with more programming ability than myself lend a hand with this??

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

:D Try this:

Go to My Project/MyEvents.vb

and put in this code:

       Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As System.Windows.Forms.StartupEventArgs) Handles Me.Startup
            [form Name here].hide()
        End Sub

That should work.

Any problems just post here...

Good Luck!! :D

Link to comment
Share on other sites

  • 0

Thanks for the reply gerry, but I'm not sure I follow. I don't have a form to show or hide. There are no forms in the project, I just want to show the pop-up notification window by itself.

Link to comment
Share on other sites

  • 0

Hello, I think I've done what you want to do.

I'm not very good at explaining but I'll do my best.

First heres the code

   
            Dim NtfThread As New Thread(AddressOf ShowNtfWin)
            NtfThread.Name = "NtfWindow"

            NtfThread.Start()


Private Sub ShowNtfWin()


        Dim myNtfWin As New VbPowerPack.NotificationWindow

        myNtfWin.Blend = New VbPowerPack.BlendFill(VbPowerPack.BlendStyle.Vertical, System.Drawing.SystemColors.Highlight, System.Drawing.SystemColors.Window)
        myNtfWin.DefaultText = Nothing
        myNtfWin.DefaultTimeout = 5000
        myNtfWin.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        myNtfWin.ForeColor = System.Drawing.SystemColors.HighlightText
        myNtfWin.RightToLeft = System.Windows.Forms.RightToLeft.No
        myNtfWin.ShowStyle = VbPowerPack.NotificationShowStyle.Fade


        AddHandler myNtfWin.Click, AddressOf ClickNtf

        AddHandler myNtfWin.Closed, AddressOf CloseNtf

        If isHyper Then

            'Exit Sub
            myNtfWin.TextIsHyperLink = True
            myNtfWin.DefaultText = "An error as occured. Click for more info"
            myNtfWin.DefaultTimeout = 10000
            myNtfWin.Notify()

        Else

            'Exit Sub
            myNtfWin.DefaultText = strErrMsg
            myNtfWin.TextIsHyperLink = False
            myNtfWin.Notify()

        End If

        Application.Run()



    End Sub

    Private Sub ClickNtf(ByVal sender As Object, ByVal e As EventArgs)

            MessageBox.Show(strErrMsg)

    End Sub

    Private Sub CloseNtf(ByVal sender As Object, ByVal e As VbPowerPack.NotificationClosedEventArgs)

        Application.ExitThread()

    End Sub

After countless hours of trying I founded out that if you call the notification window without a form or in this case in a new thread, the notification window start to appear when you call .notify but it will disappear as soon as the sub's end. That why i used application.run because it keeps the thread running when you get a the end of the sub . I'm not sure if this is the best way of doing it but at least it works. I've also added a handler to the onClosed event of the notification window to exit the running thread.

Well, I hope this will help you

Good luck :)

Link to comment
Share on other sites

  • 0

WOW - that worked like a charm. Now to figure out why it works. I tried all kinds of things with trying to get around not having to show a dialog - and you are right, I could get it to start drawing then disappear quickly. Always had to go back to Form.ShowDialog. I would have never thought starting it inside it's own thread would have been the trick to get it to display.

Thanks for teaching me something - I am in your debt!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.