本文介绍了从自定义消息框类生成对话框结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在开发类似以下内容的自定义消息框类-

Dear friend,

I am developing a custom messagebox class like the following-

Public Class MyCustomMsgBox

    Private MyForm As Form = New Form
    Private lblHeadline As Label = New Label
    Private lblMessageBody As Label = New Label
    Private btnNo As Button = New Button
    Private btnOk As Button = New Button
    Private btnYes As Button = New Button

    Public Sub New(ByVal Message As String)
        With MyForm
            .Width = 438
            .Height = 214
            .Controls.AddRange(New Control() {lblHeadline, lblMessageBody, btnNo, btnYes, btnOk})
        End With
    End Sub

    Public Shared Function ShowErrorMsg(ByVal ErrorMessage As String) As Windows.Forms.DialogResult
        Dim obj As MyCustomMsgBox = New MyCustomMsgBox(ErrorMessage)
        obj.MyForm.ShowDialog()
    End Sub

    Public Shared function ShowSuccessMsg(ByVal SuccessMessage As String) As Windows.Forms.DialogResult
       ''some code
    End Sub

    Public Shared Function AskQuestions(ByVal Questions As String) As Windows.Forms.DialogResult
       ''some code
    End Sub

    Public Shared Function ShowExceptions(ByVal ExMessage As String) As Windows.Forms.DialogResult
       ''some code
    End Sub


    ''Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
    ''  Windows.Forms.DialogResult.No()
    ''End Sub

End Class



这些功能具有相关的图形,颜色,标题和标题.

btnOk将返回DialogResult.Ok,btnNo将返回DialogResult.No,btnYes将返回DialogResult.Yes

我怎么知道按下了哪个按钮?

我不知道如何在无格式的类中处理按钮单击事件.

你能给我个主意吗?

提前谢谢您.

SKPaul



Those functions are designed with related graphics, color, title and heading.

btnOk will return DialogResult.Ok, btnNo will return DialogResult.No and btnYes will return DialogResult.Yes

How do i know that which button is pressed?

i dont know how to handle a button click event in a formless class.

Would you give me the idea?

Thank you in advance.

SKPaul

推荐答案

Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
        Me.DialogResult = DialogResult.No
End Sub



这篇关于从自定义消息框类生成对话框结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 17:16