473,322 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Create a mgbox without default button

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
5 5386
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
6
by: Frank Wilson | last post by:
Tom, It sounds to me like ASP, not ASP.NET is handling the request for WebForm1.aspx. This is most likely an IIS config issue that may have been caused by order of installation or...
5
by: Jonah Olsson | last post by:
Hello guys, I have an application which is built upon several user controls. That is, I have a default template (default.aspx) that I load a user control into (using placeholders in the...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
3
by: Beamer | last post by:
Hi I am trying to build a roating slide effect in javascript. Basically, I have a list like below <ul id="slideShowCnt"> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
I placed a button on a form menustrip for the purpose of causing the horizontal scrollbar of my form to appear so that I can access controls outside of the form's current view (the controls are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.