954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

picture on a msgbox?

can someone tell me how to put a picture on a msgbox? or even just an icon?

problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

try the following sample code.

MsgBox("Do you really wish to quit this program ?", vbOKCancel + vbQuestion, "Confirmation")
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Debasisdas code will show the default question icon. By using vbInformation, the indormation icon will show, vbExclamation will show the exclamation icon.

Did you want to add your own icon on the message box?

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

andreRet yes, I want to put my own icon or image in the msgbox can it be possible?

problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

Not with windows default message box. I have written my own message box which works wonders. Try it, its free.:)

In a module, add the following. I have uncommented a lot of the code because I'm not really using all of the message box styles.

Option Explicit

Public Function MsgQuestion(Msg As String, Title As String, FirstButton As String, SecondButton As String) As String

With frmMsgQuestion
    .lblTitle.Caption = Title
    .lblMessage.Caption = Msg
    .cmdReturn(0).Caption = FirstButton
    .cmdReturn(1).Caption = SecondButton
    '.Image1(0).Picture = .imglstMessage.ListImages(2).Picture
    '.image2(1).Picture = .imglstMessage.ListImages(3).Picture
    .Show vbModal
        DoEvents
        MsgQuestion = .Tag
        Unload frmMsgQuestion
End With
End Function

Public Function MsgCustom(Msg As String, Title As String, FirstButton As String, SecondButton As String) As String

'With frmMsgCustom
    '.lblTitle.Caption = Title
    '.lblMessage.Caption = Msg
    '.cmdReturn(0).Caption = FirstButton
    '.cmdReturn(1).Caption = SecondButton
    '.image1(0).Picture = .imglstMessage.ListImages(2).Picture
    '.image2(1).Picture = .imglstMessage.ListImages(3).Picture
    '.Show vbModal
        'DoEvents
        'MsgCustom = .Tag
        'Unload frmMsgCustom
'End With
End Function

Public Function MsgYesNo(Msg As String, Title As String, FirstButton As String, SecondButton As String) As String

'With frmMsgYesNo
    '.lblTitle.Caption = Title
    '.lblMessage.Caption = Msg
    '.cmdReturn(0).Caption = FirstButton
    '.cmdReturn(1).Caption = SecondButton
    '.image1(0).Picture = .imglstMessage.ListImages(2).Picture
    '.image2(1).Picture = .imglstMessage.ListImages(3).Picture
    '.Show vbModal
        'DoEvents
        'MsgYesNo = .Tag
        'Unload frmMsgYesNo
'End With
End Function

Public Function MsgOkOnly(Msg As String, Title As String, FirstButton As String, SecondButton As String) As String

With frmMsgOkOnly
    .lblTitle.Caption = Title
    .lblMessage.Caption = Msg
    .cmdReturn(0).Caption = FirstButton
    '.cmdReturn(1).Caption = SecondButton
    '.image1(0).Picture = .imglstMessage.ListImages(2).Picture
    '.image2(1).Picture = .imglstMessage.ListImages(3).Picture
    .Show vbModal
        DoEvents
        MsgOkOnly = .Tag
        Unload frmMsgOkOnly
End With
End Function

Public Function MsgOkCancel(Msg As String, Title As String, FirstButton As String, SecondButton As String) As String

'With frmMsgOkCancel
    '.lblTitle.Caption = Title
    '.lblMessage.Caption = Msg
    '.cmdReturn(0).Caption = FirstButton
    '.cmdReturn(1).Caption = SecondButton
    '.image1(0).Picture = .imglstMessage.ListImages(2).Picture
    '.image2(1).Picture = .imglstMessage.ListImages(3).Picture
    '.Show vbModal
        'DoEvents
        'MsgOkCancel = .Tag
       ' Unload frmMsgOkCancel
'End With
End Function


Set up your message form, which will be your new message box system in your application. Have a look at the control names and form names, otherwise an error will be raised. The code under your message form -

Private Sub cmdReturn_Click(Index As Integer)

frmMsgOkCancel.Hide
frmMsgOkCancel.Tag = cmdReturn(Index).Caption
End Sub


Under your normal form from where the message will be called, the following code -

Dim strMessage As String

strMessage = MsgQuestion("This Is My Own MessageBox. Do You Like It?", "My Message", "Ok, I Like It", "No, I Hate It")


Let me know if there is something you don't understand. This will surely give me some reputation points!:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

wow. you definitely are good at this one. just one question. are the codes that come after the apostrophes are comments? :)

thanks anyways!

problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

Yes, it is code, they are commented because I was not really using the code. You can uncomment them by deleting the apostrophe if you are going to use a custom message box or OkCancel message form.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

ok thanks a lot! you're an angel. this post will surely put your points higher! ;)

problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

It was a BIG pleasure, thanks.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You