Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Customize Msgbox buttons

Status
Not open for further replies.

xinyin

Programmer
Jan 16, 2003
81
HK
Hi all,
I want to make my own buttons in msgbox. I believe it is possible, the hint is msgbox has a constant "vbDefaultButton4" allows you to set the FOURTH button as default; but among the "given" button setting constants, the constant having most buttons (vbYesNoCancel) has only THREE buttons?
 
You cannot add or customize buttons in message box.

The fourth button is the 'Help' button which you want to add if you create a help file with your project. The help button is added with vbMsgBoxHelpButton flag and then vbDefaultButton4 flag makes sense. See the following code.
[tt]
ret = MsgBox("Continue without saving?", vbQuestion Or vbYesNoCancel Or vbMsgBoxHelpButton Or vbDefaultButton4, , "Myhelp.hlp", 10)
[/tt]
Note that when you specify the help button, you should also provide the help filename and topic in the last two arguments of the MsgBox function.

One useful customization is changing the icon in the message box to some user-defined icon (say your application icon) but that also requires Win32 API. VB's Msgbox function does not support this.

You better make your own message box dialog and customize it the way you want.
 
>make my own buttons

What precisely do you want to do? Although not straightforward, it is possible to modify the VB messagebox within certain limits.
 
Sorry I did not make my question clear enough. I mean I want to know if VB allows us to do something in the msgbox syntax so that I can choose any text I like for the buttons, not only "Ok", "Yes", "No", "Cancel"... and if the number of buttons can be set too.
Although this can be done by making a new form looks like a message box, but this is more complicated - you have to load the form, and such form is only suitable for one situation; but if I use msgbox this can be done by just one line of code and without creating forms, also if the situation changes then just change the parameters.
 
I do believe that Hypetia answered this in his first line...
Hypetia said:
You cannot add or customize buttons in message box.

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
xinyin said:
and such form is only suitable for one situation

You can load different number of command buttons and set their caption at runtime. Then when then buttons are clicked read the caption to do the oppropriate action.

Tom
 
Also once your custom messagebox form is created you can call it in one line of code by referencing a public sub on your custom messagebox form. For example

call LoadMyMessageBox("Text","Command1Caption","Command1Caption", etc...)

Then the public sub on your messagebox form

Public Sub LoadMyMessageBox(Text as string,Caption1 as string, Caption2 as string, etc...

Then load text,command buttons and set captions.

Tom
 
As I said, there are indeed ways of doing this but they are not straightforward and there are limits to what you can do. We've illustrated the technique shown on the vbnet website on several occassions in this forum (including a variation that uses a timer to trap the creation of the dialog rather thasn the CBT hoook)
 
strongm, Yes you are right..


________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
If you want to have complete control over what goes on your message box, you can just use your own form, too. Make it a dialog form, put what you like on it, and show it instead of calling the msgbox function. You can also make a wrapper function (say "MyMsgBox") that plays around with the captions of command buttons, etc. shows the form, and returns whatever value you want.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top