Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Messagebox that asks a question

81 views
Skip to first unread message

Darin

unread,
Aug 7, 2003, 7:46:29 AM8/7/03
to
There are many places in my software that I need to ask for a date
before I do something. What I would like to do is create a box similar
to the MessageBox, but that asks for text (datetimepicker) input instead
of just buttons.

I know I can do this, I just don't know the best way.

If I create a form that asks for the date, the user enters the date,
then clicks ok. What is the BEST way to get that date back to the
calling form?

I want it so the calling form code is:

dim gldate as date
gldate=AskDate()

Thanks.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Mattias Sjögren

unread,
Aug 7, 2003, 8:15:53 AM8/7/03
to
Darin,

>What is the BEST way to get that date back to the
>calling form?

I would expose it as a property of the form class.

Public ReadOnly Property [Date] As Date
Get
Return YourDateTimePicker.Value
End Get
End Property

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Tom Spink

unread,
Aug 7, 2003, 9:16:03 AM8/7/03
to
Hi, See Mattias' reply for a nice way of doing it, but also, if you want it
in the form you specified, like dtDate = AskDate(), then...

In your form, create a public function called AskDate, with a return value
of date.

Public Function AskDate() As Date
Me.ShowDialog()
Return YourDateTimePicker.Value
End Function

Then...

Dim fAskDate As New frmAskDate
Dim dtDate As Date = frmAskDate.AskDate()

--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit


"Darin" <darin_nospam@nospamever> wrote in message
news:uYKWLmNX...@TK2MSFTNGP10.phx.gbl...

Herfried K. Wagner [MVP]

unread,
Aug 7, 2003, 9:42:53 AM8/7/03
to
Hello,

"Darin" <darin_nospam@nospamever> schrieb:


> If I create a form that asks for the date, the user enters the date,
> then clicks ok. What is the BEST way to get that date back to the
> calling form?

\\\
Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

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

Private components As System.ComponentModel.IContainer

Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker

<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnOK = New System.Windows.Forms.Button()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.SuspendLayout()
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnCancel.Location = New System.Drawing.Point(176, 144)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(80, 24)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
'
'btnOK
'
Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnOK.Location = New System.Drawing.Point(88, 144)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(80, 24)
Me.btnOK.TabIndex = 1
Me.btnOK.Text = "OK"
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(16, 24)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(240, 20)
Me.DateTimePicker1.TabIndex = 2
'
'Form2
'
Me.AcceptButton = Me.btnOK
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(274, 184)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DateTimePicker1,
Me.btnOK, Me.btnCancel})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form2"
Me.ShowInTaskbar = False
Me.Text = "Select date"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub btnOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnOK.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

Private Sub btnCancel_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub

Public Property [Date]() As Date
Get
Return Me.DateTimePicker1.Value
End Get
Set(ByVal Value As Date)
Me.DateTimePicker1.Value = Value
End Set
End Property
End Class
///

Test call:

\\\
Private Sub Button1_Click(...) ...
Dim f As New Form2()
If f.ShowDialog(Me) = DialogResult.OK Then
MsgBox(f.Date.ToString())
Else
MsgBox("Cancelled")
End If
End Sub
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Darin

unread,
Aug 7, 2003, 12:24:35 PM8/7/03
to
Worked perfectly - thanks a bunch.
0 new messages