sirbounty
asked on
Accessing form controls (without 'sharing')
Let's say I have frmMain and a label on it that displays the date.
I want to be able to click the date, and have a second form frmDate display, which only contains the calendar control, and update the label on frmMain with the date selected.
Currently, I'm running into "Reference to a non-shared member requires an object reference" while trying to simply use frmMain.Label1.Text=Cal.Se lectionSta rt
I sort of understand why that is, and have read that using the shared keyword may alleviate the problem, however, one twist that I have is that frmMain may not be frmMain 'all the time'.
Ideally, I'd love to be able to pass the Date clicked back to the form's parent (I'm displaying with showdialog), but that property appears to be empty anyway.
Any way to easily accomplish what I'm after here? Please ask if anything needs clarifying. Thanx
I want to be able to click the date, and have a second form frmDate display, which only contains the calendar control, and update the label on frmMain with the date selected.
Currently, I'm running into "Reference to a non-shared member requires an object reference" while trying to simply use frmMain.Label1.Text=Cal.Se
I sort of understand why that is, and have read that using the shared keyword may alleviate the problem, however, one twist that I have is that frmMain may not be frmMain 'all the time'.
Ideally, I'd love to be able to pass the Date clicked back to the form's parent (I'm displaying with showdialog), but that property appears to be empty anyway.
Any way to easily accomplish what I'm after here? Please ask if anything needs clarifying. Thanx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you can close the date form when you have selected a date, you can also create a property to read the date from:
Public Class frmDate
Private mSelDate As Date
Public Function SelDate() As Date
Return mSelDate
End Function
Private Sub MonthCalendar1_DateSelecte d(ByVal sender As Object, ByVal e As System.Windows.Forms.DateR angeEventA rgs) Handles MonthCalendar1.DateSelecte d
mSelDate = e.End
Me.DialogResult = Windows.Forms.DialogResult .OK
Me.Close()
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New frmDate
If frm.ShowDialog() = Windows.Forms.DialogResult .OK Then
Label1.Text = frm.SelDate.ToString("d")
End If
End Sub
End Class
Public Class frmDate
Private mSelDate As Date
Public Function SelDate() As Date
Return mSelDate
End Function
Private Sub MonthCalendar1_DateSelecte
mSelDate = e.End
Me.DialogResult = Windows.Forms.DialogResult
Me.Close()
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New frmDate
If frm.ShowDialog() = Windows.Forms.DialogResult
Label1.Text = frm.SelDate.ToString("d")
End If
End Sub
End Class
ASKER
Hmm - yes, I will be closing it once the date is selected.
I'll try this out. Thanx.
I'll try this out. Thanx.
ASKER
Works great! Thanx again!! :^)
ASKER
Thanx! :^)