By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

Create a mgbox without default button

P: n/a
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,
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You want an alert with no buttons at all?

on a windows form a small modal form with a timer?


"Wonder" <Wo****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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,

Nov 21 '05 #2

P: n/a
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****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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,

Nov 21 '05 #3

P: n/a
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.com> 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****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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,


Nov 21 '05 #4

P: n/a
Since
'Throws an exception
MessageBox.Show("Some Notice", "Have a nice day.",
MessageBoxButtons.OKCancel, MessageBoxIcon.None, -1,
MessageBoxOptions.DefaultDesktopOnly)

and

'Doesn't provide facility to set a default button
MsgBox("Some Notice", MsgBoxStyle.OKCancel, "Have a nice day")

Therefore try this:

Sub DoIT
Dim f As frmMessageBox = New frmMessageBox("Some Notice",
frmMessageBox.MyStyle.msYes + frmMessageBox.MyStyle.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.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.Text = Title
Me.lblMessage.Text = Message
m_Buttons = Buttons
SetButtons(Buttons, DefaultButton)

Debug.WriteLine(Buttons.ToString)

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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
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.SuspendLayout()
'
'lblMessage
'
Me.lblMessage.BackColor = System.Drawing.Color.White
Me.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblMessage.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.lblMessage.Location = New System.Drawing.Point(16, 8)
Me.lblMessage.Name = "lblMessage"
Me.lblMessage.Size = New System.Drawing.Size(504, 280)
Me.lblMessage.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(448, 296)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Visible = False
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(368, 296)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Visible = False
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(288, 296)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 3
Me.Button3.Visible = False
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(208, 296)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 4
Me.Button4.Visible = False
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(128, 296)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 5
Me.Button5.Visible = False
'
'frmMessageBox
'
Me.AutoScaleBaseSize = 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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "frmMessageBox"
Me.ResumeLayout(False)

End Sub

#End Region

Public Shadows Sub Show()
MyBase.ShowDialog()
End Sub

Private Sub frmMessageBox_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Private Sub SetButtons(ByVal Buttons As MyStyle, ByVal DefaultButton As
Integer)

Dim iButtonCount As Integer

'Cancels go to the right
If (Buttons And MyStyle.msCancel) And MyStyle.msCancel =
MyStyle.msCancel Then
iButtonCount = iButtonCount + 1
SetButton("&Cancel", DialogResult.Cancel, 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("&Abort", DialogResult.Cancel, iButtonCount, DefaultButton)
'End If

If (Buttons And MyStyle.msIgnore) And MyStyle.msIgnore =
MyStyle.msIgnore Then
iButtonCount = iButtonCount + 1
SetButton("&Ignore", DialogResult.Ignore, iButtonCount, DefaultButton)
End If

'If Buttons And MyStyle.msRetry = MyStyle.msRetry Then
' iButtonCount = iButtonCount + 1
' SetButton("&Retry", DialogResult.Cancel, iButtonCount, DefaultButton)
'End If

If (Buttons And MyStyle.msYes) And MyStyle.msYes = MyStyle.msYes Then
iButtonCount = iButtonCount + 1
SetButton("&Yes", DialogResult.Yes, 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.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button1
End If
Case 2
Button2.Text = Caption
Button2.Tag = BtnTag
Button2.Visible = True
Button2.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button2
End If
Case 3
Button3.Text = Caption
Button3.Tag = BtnTag
Button3.Visible = True
Button3.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button3
End If
Case 4
Button4.Text = Caption
Button4.Tag = BtnTag
Button4.Visible = True
Button4.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button4
End If
Case 5
Button5.Text = Caption
Button5.Tag = BtnTag
Button5.Visible = True
Button5.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button5
End If
End Select

End Sub

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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*******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.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.com> 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****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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,



Nov 21 '05 #5

P: n/a
I have a message box with OK and Cancel, but I want to force the user to
explicitly click on one of the buttons. It shouldn't have a default button
neither ESC.

Thanks all.
"AMDRIT" wrote:
Since
'Throws an exception
MessageBox.Show("Some Notice", "Have a nice day.",
MessageBoxButtons.OKCancel, MessageBoxIcon.None, -1,
MessageBoxOptions.DefaultDesktopOnly)

and

'Doesn't provide facility to set a default button
MsgBox("Some Notice", MsgBoxStyle.OKCancel, "Have a nice day")

Therefore try this:

Sub DoIT
Dim f As frmMessageBox = New frmMessageBox("Some Notice",
frmMessageBox.MyStyle.msYes + frmMessageBox.MyStyle.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.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.Text = Title
Me.lblMessage.Text = Message
m_Buttons = Buttons
SetButtons(Buttons, DefaultButton)

Debug.WriteLine(Buttons.ToString)

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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
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.SuspendLayout()
'
'lblMessage
'
Me.lblMessage.BackColor = System.Drawing.Color.White
Me.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblMessage.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.lblMessage.Location = New System.Drawing.Point(16, 8)
Me.lblMessage.Name = "lblMessage"
Me.lblMessage.Size = New System.Drawing.Size(504, 280)
Me.lblMessage.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(448, 296)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Visible = False
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(368, 296)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Visible = False
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(288, 296)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 3
Me.Button3.Visible = False
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(208, 296)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 4
Me.Button4.Visible = False
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(128, 296)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 5
Me.Button5.Visible = False
'
'frmMessageBox
'
Me.AutoScaleBaseSize = 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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "frmMessageBox"
Me.ResumeLayout(False)

End Sub

#End Region

Public Shadows Sub Show()
MyBase.ShowDialog()
End Sub

Private Sub frmMessageBox_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Private Sub SetButtons(ByVal Buttons As MyStyle, ByVal DefaultButton As
Integer)

Dim iButtonCount As Integer

'Cancels go to the right
If (Buttons And MyStyle.msCancel) And MyStyle.msCancel =
MyStyle.msCancel Then
iButtonCount = iButtonCount + 1
SetButton("&Cancel", DialogResult.Cancel, 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("&Abort", DialogResult.Cancel, iButtonCount, DefaultButton)
'End If

If (Buttons And MyStyle.msIgnore) And MyStyle.msIgnore =
MyStyle.msIgnore Then
iButtonCount = iButtonCount + 1
SetButton("&Ignore", DialogResult.Ignore, iButtonCount, DefaultButton)
End If

'If Buttons And MyStyle.msRetry = MyStyle.msRetry Then
' iButtonCount = iButtonCount + 1
' SetButton("&Retry", DialogResult.Cancel, iButtonCount, DefaultButton)
'End If

If (Buttons And MyStyle.msYes) And MyStyle.msYes = MyStyle.msYes Then
iButtonCount = iButtonCount + 1
SetButton("&Yes", DialogResult.Yes, 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.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button1
End If
Case 2
Button2.Text = Caption
Button2.Tag = BtnTag
Button2.Visible = True
Button2.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button2
End If
Case 3
Button3.Text = Caption
Button3.Tag = BtnTag
Button3.Visible = True
Button3.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button3
End If
Case 4
Button4.Text = Caption
Button4.Tag = BtnTag
Button4.Visible = True
Button4.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button4
End If
Case 5
Button5.Text = Caption
Button5.Tag = BtnTag
Button5.Visible = True
Button5.DialogResult = BtnTag
If DefaultButton = Index Then
Me.AcceptButton = Button5
End If
End Select

End Sub

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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*******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.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.com> 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****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.