We help IT Professionals succeed at work.

Can I change MsgBox Constants Graphics in VB5?

imajdn asked
Medium Priority
Last Modified: 2012-06-27
I am using the MsgBox function in VB5 Enterprise and I would like to use custom graphics for the icons:

vbCritical        16    Display Critical Message icon.
vbQuestion        32    Display Warning Query icon.
vbExclamation     48    Display Warning Message icon.
vbInformation     64    Display Information Message icon.

Is it posssible to change these graphics?

Ideally I would create my own form but I'm not too sure how to pass parameters to a form.
How do you pass parameters to a form in VB?
If anyone can answer either of these questions, preferably the last as I would like to use
custom fonts and layouts as well, then I'll give top marks.

Watch Question

For your second question:

There is nothing like passing parameters to a form. However, you can have public Properties and/or Mehods in a form. And you can set those Properties and/or call the Methods from some other modules any time you want.  Think about it, it may help you.

You can pass parameters to a subroutine and from there, based on the parameters, load the form.


Are you talking about passing parameters to the Form_Load method?

Rather than having me guess can you give me an example of the calling and
called methods? I'd rather get a example working solution than have to work it
out myself using a few tips.


Sorry I was not clear, but I did not have time to put an example.  I dont think that you can actually change the msgbox.  This is just a quick example of passing arguments to a subroutine and then loading a form with that subroutine inplace of the msgbox.  All you have to do, is make the form look like a msgbox.

Sub Command1_Click()

  Dim MsgBoxType as Integer


  If ErrorOrSomeReasonForAMsgBox Then
     If ErrorOrSomeReasonForAMsgBox = "Critical Message" Then
        Call DisplayFormLikeAMsgBox(1)
     End If
     If ErrorOrSomeReasonForAMsgBox = "Warning Query" Then
        Call DisplayFormLikeAMsgBox(2)
     End if
     ...Continue for the rest of the msgbox types
End Sub

Private Sub DisplayFormLikeAMsgBox(TypeOfIcon as Integer)
   If TypeOfIcon = 1 Then
      Form2.Picture1.Picture = "CriticalIcon"
      Form2.Load vbModal, Me
   end if
   If TypeOfIcon = 2 then
      Form2.Picture1.Picture = "WarningIcon"
      Form2.Load vbModal, Me
   end if
.And so on for the rest of the possible calls.

End Sub

This might not be what you were looking for in the first place, but it is a work-around the fact that you cant change the icon in the msgbox.  You could make the above code better with Select Case statements and things like that, but it is just an example.


I'm sorry to be blunt but what you have given me is a pile of tosh.

You do not load a form using:

         Form2.Load vbModal, Me

you declare the form, set the form, load the form, then show the form: e.g.

    Dim f2 As  Form2

    Set f2 = New  Form2
    Load f2
    f2.Show vbModal

AND what you have given me doesn't show any picture at all.


   Set f2.Picture1.Picture = LoadPicture(CurDir & "test.bmp")

just does not show the picture. I have tried the statement before and
after the Load Statement.
It is just an idea but why don't you try out a solution then give the results of
that solution. I am spending time trying to adapt what you give me into a
working solution and the whole point of Experts Exchange is that YOU
spend the time working out the solution and I give you the points.
Sorry but giving me what appears to be pseudo code isn't good enough.

Sorry, I didnt realize who I was dealing with.  I assumed that you would be able to use the code as an example and figure out what you needed to do.  I will write a sample and post it on the web so that you can just cut and paste my code into your project.  Sorry for the trouble.  Ill post the answer when I get a chance.
Unlock this solution and get a sample of our free trial.
(No credit card required)


Thank you jf26028.
That is more like what I was expecting. I don't mind giving out full marks
if the answer is good. It's just that I don't have time to second guess someones
pseudo code.

Cheers again.

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.