Me.Close

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von Betzi.

    Hey
    hab da gerade ein komisches Problem.
    Habe mir einen Messagerequester gemacht. Der Funktioniert auch soweit.
    So wenn ich sage Me.Close() kann ich danach dann noch sagen Me.Opacity = 0 ???
    Weil ich damit abfragen will ob das Fenster bereits geöffnet wurde, sodass ich nicht mehrmals das Fenster öffne.

    Blos scheint das nicht so recht zu funktionieren

    VB.NET-Quellcode

    1. If Me.Visible Then
    2. ' ich bin sichtbar
    3. End If

    So einen nicht-modalen Dialog anzeigen

    VB.NET-Quellcode

    1. If dlg Is Nothing OrElse dlg.IsDisposed Then
    2. dlg = New FormX
    3. End If
    4. If Not dlg.Visible Then
    5. dlg.Show()
    6. End If
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hm wenn man das mit "Me.Visible()" abfragen kann muss der Fehler woanders stecken -.-

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Option Explicit On : Option Strict On
    2. Public Class Messagerequester
    3. Dim Breite, Höhe, Button As Integer
    4. Public Sub Zeige1(ByVal Title As String, ByVal Message As String, ByVal Button01 As String, ByVal picture As Bild) ' As Boolean
    5. If Me.Opacity = 0 Then
    6. Btn2.Visible = False
    7. If LblMeld.Text <> Message Then
    8. LblMeld.Text = Message
    9. Me.AutoSize = True
    10. End If
    11. Btn1.Text = Button01
    12. Me.Text = Title
    13. Img(picture)
    14. Einst()
    15. End If
    16. End Sub
    17. Public Sub Zeige2(ByVal Title As String, ByVal Message As String, ByVal Button01 As String, ByVal Button02 As String, ByVal picture As Bild) ' As String
    18. If Me.Opacity = 0 Then
    19. Btn2.Visible = True
    20. If LblMeld.Text <> Message Then
    21. LblMeld.Text = Message
    22. Me.AutoSize = True
    23. End If
    24. Btn2.Text = Button02
    25. Btn1.Text = Button01
    26. Me.Text = Title
    27. Img(picture)
    28. Einst()
    29. End If
    30. End Sub
    31. Public Sub Zeige1(ByVal Title As String, ByVal Message As String, ByVal Button01 As String, ByVal Font As Font, ByVal picture As Bild) ' As Boolean
    32. If Me.Opacity = 0 Then
    33. Btn2.Visible = False
    34. If LblMeld.Text <> Message Then
    35. LblMeld.Text = Message
    36. Me.AutoSize = True
    37. End If
    38. Btn1.Text = Button01
    39. Me.Text = Title
    40. Me.Font = Font
    41. Img(picture)
    42. Einst()
    43. End If
    44. End Sub
    45. Public Sub Zeige2(ByVal Title As String, ByVal Message As String, ByVal Button01 As String, ByVal Button02 As String, ByVal Font As Font, ByVal picture As Bild) ' As String
    46. If Me.Opacity = 0 Then
    47. Btn2.Visible = True
    48. If LblMeld.Text <> Message Then
    49. LblMeld.Text = Message
    50. Me.AutoSize = True
    51. End If
    52. Btn2.Text = Button02
    53. Btn1.Text = Button01
    54. Me.Text = Title
    55. Me.Font = Font
    56. Img(picture)
    57. Einst()
    58. End If
    59. End Sub
    60. Private Sub Einst()
    61. Höhe = Me.Height
    62. If LblMeld.Height > 100 Then
    63. Höhe += (Btn1.Height + 25)
    64. End If
    65. Breite = Me.Width
    66. Me.AutoSize = False
    67. Me.Height = Höhe
    68. Breite += 20
    69. Me.Width = Breite
    70. Btn1.SetBounds(15, Höhe - (Btn1.Height + 35), Btn1.Width, Btn1.Height)
    71. Btn2.SetBounds(Breite - (Btn2.Width + 20), Höhe - (Btn2.Height + 35), Btn2.Width, Btn2.Height)
    72. PicBMess.SetBounds(15, 15, 49, 49)
    73. MyBase.Opacity = 100
    74. Me.ShowDialog()
    75. End Sub
    76. Private Sub Img(ByVal Picture As Integer)
    77. If Picture = 1 Then
    78. PicBMess.Image = MainForm.information
    79. ElseIf Picture = 2 Then
    80. PicBMess.Image = MainForm.warning
    81. ElseIf Picture = 3 Then
    82. PicBMess.Image = MainForm.important
    83. ElseIf Picture = 4 Then
    84. PicBMess.Image = MainForm.critical
    85. ElseIf Picture = 5 Then
    86. PicBMess.Image = MainForm.question
    87. Else
    88. PicBMess.Image = Nothing
    89. End If
    90. End Sub
    91. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click
    92. MainForm.Messagereturn = Btn1.Text
    93. Btn2.SetBounds(0, 0, Btn2.Width, Btn2.Height)
    94. Me.Close()
    95. Me.Opacity = 0
    96. End Sub
    97. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn2.Click
    98. MainForm.Messagereturn = Btn2.Text
    99. Btn2.SetBounds(0, 0, Btn2.Width, Btn2.Height)
    100. Me.Close()
    101. Me.Opacity = 0
    102. End Sub
    103. Enum Bild
    104. information = 1
    105. warning = 2
    106. important = 3
    107. critical = 4
    108. question = 5
    109. nix = 0
    110. End Enum
    111. End Class


    Fals hilfreich:
    "Das Formular, das bereits modal angezeigt wird, kann nicht als modales Dialogfeld angezeigt werden. Schließen Sie das Formular, bevor Sie showDialog aufrufen."

    EDIT: ??? Keiner eine Idee warum er das macht ?? Also eine Exception schmeisst.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Zim“ ()

    Es Tritt im Moment nicht mehr auf, ist aber ein potenzieller Fehler.
    Also wenn meine Software zu schnell hintereinander das Fenster, also den Messagerequester aufruft kommt die Exception das die Form noch offen ist ...
    Dabei überprüfe ich eigentlich mithilfe von "If Me.Opacity = 0 Then" ob die Form noch offen ist.
    Was kann ich nun noch machen um zu Prüfen ob die Form wirklich schon zu ist ???
    Ich hab keine lust das mit Try Catch auf zu fangen...

    Gruß Zim
    ich würde vielleicht me.hide anstatt me.close benutzen, dann kannst du mit

    VB.NET-Quellcode

    1. if me.visible = true

    abfragen, ob das fenster schon offen ist... und das opacity kannst du weg lassen, falls ich verstanden habe, was du machen willst...