Helpmij.nl
Helpmij.nl
Helpmij.nl
Steun Helpmij.nl! Klik hier     Computerprobleem? Klik hier!

Quote

Weergeven resultaten 1 tot 10 van 10

Onderwerp: Taskdialog gebruiken i.p.v Messagebox

  • Vraag is opgelost
  1. #1
    Senior Member hanonymouss's avatar
    Geregistreerd
    7 september 2011
    Locatie
    Antwerpen
    Afstand tot server
    ±185 km

    Taskdialog gebruiken i.p.v Messagebox

    Hallo allemaal,

    Ik heb een functie gevonden voor VB.net dat je taskdialog kunt gebruiken in de plaats van de klassieke messagebox.(Alleen voor Vista en 7) De code werkt uitstekend maar ik kan de taskdialog niet gebruiken zoals bij een messagebox om bijvoorbeeld gebruikers te laten kiezen tussen ja of nee. Dit kun je doen met messagebox maar taskdialog

    Bij een messagebox werkt deze wel:


    CPP Code:
    1
    2
    3
    4
    5
    6
    
    dim info as MsgBoxResult
     t = MessageBox.Show("Wilt u toch doorgaan ?", "Bevestiging", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
     If t = MsgBoxResult.Yes Then
     label1.text = "U hebt voor JA gekozen"
     ElseIf t = MsgBoxResult.No Then
     label1.text = "U hebt voor Nee gekozen"


    Als ik dit doe voor de taskdialog werkt dit niet. Hier de volledige code:

    CPP Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    
    Imports System.Runtime.InteropServices
    Public Class Form1
        Dim t As TaskDialogResult
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            t = TaskDialog.Show(Me, "Wilt u toch doorgaan ?", "Bevestiging", "Bevestiging", TaskDialogButtons.Yes Or TaskDialogButtons.No, TaskDialogIcon.Question)
            If t = TaskDialogResult.Yes Then
                label1.text = "U hebt voor JA gekozen"
            ElseIf t = TaskDialogResult.No Then
                label1.text = "U hebt voor Nee gekozen"
     
            End If
        End Sub
    End Class
     
    Public Class TaskDialog
        <DllImport("comctl32.dll", CharSet:=CharSet.Unicode, EntryPoint:="TaskDialog")> _
        Private Shared Function _TaskDialog(hWndParent As IntPtr, hInstance As IntPtr, pszWindowTitle As [String], pszMainInstruction As [String], pszContent As [String], dwCommonButtons As Integer, _
       pszIcon As IntPtr, pnButton As Integer) As Integer
        End Function
     
     
     
        Public Shared Function Show(owner As IWin32Window, text As String) As TaskDialogResult
            Return Show(owner, text, Nothing, Nothing, TaskDialogButtons.OK)
        End Function
     
        Public Shared Function Show(owner As IWin32Window, text As String, instruction As String) As TaskDialogResult
            Return Show(owner, text, instruction, Nothing, TaskDialogButtons.OK, 0)
        End Function
     
        Public Shared Function Show(owner As IWin32Window, text As String, instruction As String, caption As String) As TaskDialogResult
            Return Show(owner, text, instruction, caption, TaskDialogButtons.OK, 0)
        End Function
     
        Public Shared Function Show(owner As IWin32Window, text As String, instruction As String, caption As String, buttons As TaskDialogButtons) As TaskDialogResult
            Return Show(owner, text, instruction, caption, buttons, 0)
        End Function
     
        Public Shared Function Show(owner As IWin32Window, text As String, instruction As String, caption As String, buttons As TaskDialogButtons, icon As TaskDialogIcon) As TaskDialogResult
            Return ShowInternal(owner.Handle, text, instruction, caption, buttons, icon)
        End Function
     
     
        Public Shared Function Show(text As String) As TaskDialogResult
            Return Show(text, Nothing, Nothing, TaskDialogButtons.OK)
        End Function
     
        Public Shared Function Show(text As String, instruction As String) As TaskDialogResult
            Return Show(text, instruction, Nothing, TaskDialogButtons.OK, 0)
        End Function
     
        Public Shared Function Show(text As String, instruction As String, caption As String) As TaskDialogResult
            Return Show(text, instruction, caption, TaskDialogButtons.OK, 0)
        End Function
     
        Public Shared Function Show(text As String, instruction As String, caption As String, buttons As TaskDialogButtons) As TaskDialogResult
            Return Show(text, instruction, caption, buttons, 0)
        End Function
     
        Public Shared Function Show(text As String, instruction As String, caption As String, buttons As TaskDialogButtons, icon As TaskDialogIcon) As TaskDialogResult
            Return ShowInternal(IntPtr.Zero, text, instruction, caption, buttons, icon)
        End Function
     
     
        Private Shared Function ShowInternal(owner As IntPtr, text As String, instruction As String, caption As String, buttons As TaskDialogButtons, icon As TaskDialogIcon) As TaskDialogResult
            Dim p As Integer
            If _TaskDialog(owner, IntPtr.Zero, caption, instruction, text, CInt(buttons), _
             New IntPtr(CInt(icon)), p) <> 0 Then
                Throw New InvalidOperationException("Er is iets vreemds gebeurd")
            End If
     
            Select Case p
                Case 1
                    Return TaskDialogResult.OK
                Case 2
                    Return TaskDialogResult.Cancel
                Case 4
                    Return TaskDialogResult.Retry
                Case 6
                    Return TaskDialogResult.Yes
                Case 7
                    Return TaskDialogResult.No
                Case 8
                    Return TaskDialogResult.Close
                Case Else
                    Return TaskDialogResult.None
            End Select
        End Function
     
    End Class
     
    <Flags()> _
    Public Enum TaskDialogButtons
        OK = &H1
        Cancel = &H8
        Yes = &H2
        No = &H4
        Retry = &H10
        Close = &H20
    End Enum
     
    Public Enum TaskDialogIcon
        Information = UInt16.MaxValue - 2
        Warning = UInt16.MaxValue
        [Stop] = UInt16.MaxValue - 1
        Question = 0
     
        SecurityWarning = UInt16.MaxValue - 5
        SecurityError = UInt16.MaxValue - 6
        SecuritySuccess = UInt16.MaxValue - 7
        SecurityShield = UInt16.MaxValue - 3
        SecurityShieldBlue = UInt16.MaxValue - 4
        SecurityShieldGray = UInt16.MaxValue - 8
    End Enum
     
    Public Enum TaskDialogResult
        None
        OK
        Cancel
        Yes
        No
        Retry
        Close
    End Enum

    Graag jullie hulp

  2. #2
    Giga Senior JoZ1's avatar
    Geregistreerd
    17 december 2010
    Locatie
    Nieuwegein
    Afstand tot server
    ±90 km
    In de Dialog:

    CPP Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    Private intResult As Integer
        Private Sub JaKnop_Click() Handles JaKnop.Click
            intResult = vbYes
            Close()
        End Sub
        Private Sub NeeKnop_Click() Handles NeeKnop.Click
            intResult = vbNo
            Close()
        End Sub
        Private Sub Form_Close() Handles MyBase.FormClosed
            If intResult <> vbYes Then intResult = vbNo
        End Sub
        Public ReadOnly Property Result() As Integer
            Get
                Result = intResult
            End Get
        End Property

    In het form dat de Dialog aanroept:

    CPP Code:
    1
    2
    3
    4
    5
    
    Private Sub Open_Form()
            Dim a As New NaamDialog
            a.ShowDialog()
            If a.Result = vbYes Then MsgBox("JA") Else MsgBox("NEE")
        End Sub




    "Microsoft is not the answer. Microsoft is the question. NO is the answer."- E. Naggum

  3. #3
    Senior Member hanonymouss's avatar
    Geregistreerd
    7 september 2011
    Locatie
    Antwerpen
    Afstand tot server
    ±185 km

    Foutmelding

    Ik krijg enkele foutmelding:

    - type naamdialog is not defined
    - Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    Wat bedoel je met (naamdialog) ?
    Laatst aangepast door Tha Devil : 12 maart 2012 om 21:30 Reden: Onnodige quote verwijderd

  4. #4
    Giga Senior JoZ1's avatar
    Geregistreerd
    17 december 2010
    Locatie
    Nieuwegein
    Afstand tot server
    ±90 km
    De naam van je dialog, Form1 ofzo




    "Microsoft is not the answer. Microsoft is the question. NO is the answer."- E. Naggum

  5. #5
    Senior Member hanonymouss's avatar
    Geregistreerd
    7 september 2011
    Locatie
    Antwerpen
    Afstand tot server
    ±185 km
    Je hebt me misschien verkeerd verstaan. ik wil de ouwe messagebox vervangen door de taskdialog die we allemaal kennen op windows vista en 7.

    voorbeeld.png en nu wil ik de functie daarvan gebruiken zoals bij de messagebox.

    hier de voorbeeld project:http://www.mediafire.com/?urb2v0hcq9rbpap

  6. #6
    Giga Senior JoZ1's avatar
    Geregistreerd
    17 december 2010
    Locatie
    Nieuwegein
    Afstand tot server
    ±90 km




    "Microsoft is not the answer. Microsoft is the question. NO is the answer."- E. Naggum

  7. #7
    Senior Member hanonymouss's avatar
    Geregistreerd
    7 september 2011
    Locatie
    Antwerpen
    Afstand tot server
    ±185 km
    ik wil dat het alleen voor vista en 7 werkt. Daarom heb ik voor deze code gekozen. Ik wil alleen dat ik de functies ervan wil gebruiken zoals bij de messagebox. Dit werkt voor mij alleen als ik de (windows api pack ) gebruik. Maar dit is een dll bestand en ik wil geen setup voor mijn exe gebruiken.
    Heb je de voorbeeld project bekeken ?

  8. #8
    Giga Senior JoZ1's avatar
    Geregistreerd
    17 december 2010
    Locatie
    Nieuwegein
    Afstand tot server
    ±90 km
    Ja, ik heb je project gedownload en bij mij werkt 't ook niet...

    Je kunt wel zélf een form maken die er zo uitziet (dan kun je de code die ik in mijn eerste post gaf gebruiken).




    "Microsoft is not the answer. Microsoft is the question. NO is the answer."- E. Naggum

  9. #9
    Senior Member hanonymouss's avatar
    Geregistreerd
    7 september 2011
    Locatie
    Antwerpen
    Afstand tot server
    ±185 km
    Ik ben je zeer dankbaar voor je hulp.
    Ik zal het maar proberen met zelf gemaakte forms. (zal wel even duren ) als ik op een probleem kom dan zal ik het posten.

  10. #10
    Giga Senior JoZ1's avatar
    Geregistreerd
    17 december 2010
    Locatie
    Nieuwegein
    Afstand tot server
    ±90 km
    OK, veel succes




    "Microsoft is not the answer. Microsoft is the question. NO is the answer."- E. Naggum

Berichtenregels

  • U mag geen nieuwe discussies starten.
  • U mag niet reageren op berichten.
  • U mag geen bijlagen versturen.
  • Umag niet uw berichten bewerken.
  •  
Helpmij.nl
Helpmij.nl

Helpmij.nl en business

Partners
Sponsoren
Linkpartners
Aanbiedingen