vb.netwindows-api-code-packtaskdialog

TaskDialog as modal Dialog


I am using TaskDialog and its really nice and i like it instead of normal messagebox. However i noticed that Show() of the TaskDialog allow user to go back to form and do something... I mean its not blocking Form till user close TaskDialog clicking on OK or whatever. I checked and can't find instead of Show - ShowDialog that would block untill TaskDialog will be close. Is there a way to achieve that?

e.g code:

 Dim dialog As New TaskDialog()
        AddHandler dialog.Opened, AddressOf taskDialog_Opened
        With dialog
            dialog.Text = "Hello Task Dialog"
            dialog.Caption = "Hello Task Dialog"
            dialog.Show()       
        End With

Solution

  • The term you are looking for regarding blocking is modal. If you use the OwnerWindowHandle property you can make it modal to a form:

    Using td As New TaskDialog
        td.Caption = "Some Error "
        td.StandardButtons = TaskDialogStandardButtons.Ok
        td.Text = "Something truly horrible has happened!"
        td.OwnerWindowHandle = Me.Handle    ' current form handle
        td.Show()
    End Using
    

    If your app has more than one form showing, access will only be blocked to that owner. Also note the use of a Using block to dispose of it and free resources when done.