Since
'Throws an exception
MessageBox.Show ("Some Notice", "Have a nice day.",
MessageBoxButto ns.OKCancel, MessageBoxIcon. None, -1,
MessageBoxOptio ns.DefaultDeskt opOnly)
and
'Doesn't provide facility to set a default button
MsgBox("Some Notice", MsgBoxStyle.OKC ancel, "Have a nice day")
Therefore try this:
Sub DoIT
Dim f As frmMessageBox = New frmMessageBox(" Some Notice",
frmMessageBox.M yStyle.msYes + frmMessageBox.M yStyle.msNo, "Have a nice
day!", 0)
Dim i As Integer
i = f.ShowDialog()
MsgBox(i)
End Sub
Public Class frmMessageBox
Inherits System.Windows. Forms.Form
Public Enum MyStyle As Byte
msYes = 1
msNo = 2
msCancel = 4
msIgnore = 8
msOk = 16
End Enum
Private m_Buttons As MyStyle
#Region " Windows Form Designer generated code "
Public Sub New(ByVal Message As String, ByVal Buttons As MyStyle, ByVal
Title As String, ByVal DefaultButton As Integer)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Me.Text = Title
Me.lblMessage.T ext = Message
m_Buttons = Buttons
SetButtons(Butt ons, DefaultButton)
Debug.WriteLine (Buttons.ToStri ng)
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblMessage As System.Windows. Forms.Label
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents Button2 As System.Windows. Forms.Button
Friend WithEvents Button3 As System.Windows. Forms.Button
Friend WithEvents Button4 As System.Windows. Forms.Button
Friend WithEvents Button5 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.lblMessage = New System.Windows. Forms.Label
Me.Button1 = New System.Windows. Forms.Button
Me.Button2 = New System.Windows. Forms.Button
Me.Button3 = New System.Windows. Forms.Button
Me.Button4 = New System.Windows. Forms.Button
Me.Button5 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'lblMessage
'
Me.lblMessage.B ackColor = System.Drawing. Color.White
Me.lblMessage.B orderStyle = System.Windows. Forms.BorderSty le.Fixed3D
Me.lblMessage.F latStyle = System.Windows. Forms.FlatStyle .Flat
Me.lblMessage.L ocation = New System.Drawing. Point(16, 8)
Me.lblMessage.N ame = "lblMessage "
Me.lblMessage.S ize = New System.Drawing. Size(504, 280)
Me.lblMessage.T abIndex = 0
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(448, 296)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 1
Me.Button1.Visi ble = False
'
'Button2
'
Me.Button2.Loca tion = New System.Drawing. Point(368, 296)
Me.Button2.Name = "Button2"
Me.Button2.TabI ndex = 2
Me.Button2.Visi ble = False
'
'Button3
'
Me.Button3.Loca tion = New System.Drawing. Point(288, 296)
Me.Button3.Name = "Button3"
Me.Button3.TabI ndex = 3
Me.Button3.Visi ble = False
'
'Button4
'
Me.Button4.Loca tion = New System.Drawing. Point(208, 296)
Me.Button4.Name = "Button4"
Me.Button4.TabI ndex = 4
Me.Button4.Visi ble = False
'
'Button5
'
Me.Button5.Loca tion = New System.Drawing. Point(128, 296)
Me.Button5.Name = "Button5"
Me.Button5.TabI ndex = 5
Me.Button5.Visi ble = False
'
'frmMessageBox
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(536, 326)
Me.Controls.Add (Me.Button5)
Me.Controls.Add (Me.Button4)
Me.Controls.Add (Me.Button3)
Me.Controls.Add (Me.Button2)
Me.Controls.Add (Me.Button1)
Me.Controls.Add (Me.lblMessage)
Me.FormBorderSt yle = System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.Name = "frmMessage Box"
Me.ResumeLayout (False)
End Sub
#End Region
Public Shadows Sub Show()
MyBase.ShowDial og()
End Sub
Private Sub frmMessageBox_L oad(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
End Sub
Private Sub SetButtons(ByVa l Buttons As MyStyle, ByVal DefaultButton As
Integer)
Dim iButtonCount As Integer
'Cancels go to the right
If (Buttons And MyStyle.msCance l) And MyStyle.msCance l =
MyStyle.msCance l Then
iButtonCount = iButtonCount + 1
SetButton("&Can cel", DialogResult.Ca ncel, iButtonCount, DefaultButton)
End If
If (Buttons And MyStyle.msNo) And MyStyle.msNo = MyStyle.msNo Then
iButtonCount = iButtonCount + 1
SetButton("&No" , DialogResult.No , iButtonCount, DefaultButton)
End If
'If Buttons And MyStyle.msAbort = MyStyle.msAbort Then
' iButtonCount = iButtonCount + 1
' SetButton("&Abo rt", DialogResult.Ca ncel, iButtonCount, DefaultButton)
'End If
If (Buttons And MyStyle.msIgnor e) And MyStyle.msIgnor e =
MyStyle.msIgnor e Then
iButtonCount = iButtonCount + 1
SetButton("&Ign ore", DialogResult.Ig nore, iButtonCount, DefaultButton)
End If
'If Buttons And MyStyle.msRetry = MyStyle.msRetry Then
' iButtonCount = iButtonCount + 1
' SetButton("&Ret ry", DialogResult.Ca ncel, iButtonCount, DefaultButton)
'End If
If (Buttons And MyStyle.msYes) And MyStyle.msYes = MyStyle.msYes Then
iButtonCount = iButtonCount + 1
SetButton("&Yes ", DialogResult.Ye s, iButtonCount, DefaultButton)
End If
If (Buttons And MyStyle.msOk) And MyStyle.msOk = MyStyle.msOk Then
iButtonCount = iButtonCount + 1
SetButton("&Ok" , DialogResult.OK , iButtonCount, DefaultButton)
End If
End Sub
Private Sub SetButton(ByVal Caption As String, ByVal BtnTag As Object,
ByVal Index As Integer, ByVal DefaultButton As Integer)
Select Case Index
Case 1
Button1.Text = Caption
Button1.Tag = BtnTag
Button1.Visible = True
Button1.DialogR esult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button1
End If
Case 2
Button2.Text = Caption
Button2.Tag = BtnTag
Button2.Visible = True
Button2.DialogR esult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button2
End If
Case 3
Button3.Text = Caption
Button3.Tag = BtnTag
Button3.Visible = True
Button3.DialogR esult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button3
End If
Case 4
Button4.Text = Caption
Button4.Tag = BtnTag
Button4.Visible = True
Button4.DialogR esult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button4
End If
Case 5
Button5.Text = Caption
Button5.Tag = BtnTag
Button5.Visible = True
Button5.DialogR esult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button5
End If
End Select
End Sub
Private Sub Button_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click, Button2.Click, Button3.Click,
Button4.Click, Button5.Click
Me.DialogResult = CType(sender, Button).Tag
Close()
End Sub
End Class
"JT Lovell" <jt*******@yaho o.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
He wants to force the user to click the button rather than hitting
spacebar/enter by habit.
You can do this by using a form you create rather than MsgBox and then
setting focus to something other than the OK button.
--
JT Lovell
"Phil G." <Ph**@nospam.co m> wrote in message
news:dh******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com... Is your message REALLY what you meant to say? I don't understand the
question. You can select the msgbox buttons or I guess you don't use a
messagebox but a form, BUT without a button how do you intend to close
it?
Phil
"Wonder" <Wo****@discuss ions.microsoft. com> wrote in message
news:52******** *************** ***********@mic rosoft.com... How can I create or use the msgobx to show a message without a default
button. The user has explicity to click on the button, so the msgbox
closes
it.
Thanks,