Right up front, I'm writing in vb code, not c#.
I've checked out the suggested forum subjects and none apply,(that I could find) so here it is. I'm relatively new to vb.net. (come from vb6)
I'm creating a user control_1
which contains textboxes and a button. Control_1
inherits from another user control_2
(a few textboxes and the calendar form button). When I press the button it launches a Calendar form containing a CalendarControl
.
Works fine so far.
Now I need to return the CalendarControl
value on it's Calendar form back to the unseated user control_1
. I am talking design time here, User Control_1
is not seated on a form yet.
I do not want to trigger the calendar form from it seated form because I want this proccess to be encapsulated.
I wrote the code as a forms based app to make sure my logic and app worked. Now I'm trying to move the code and constituent controls into a control library.
I've tried calling Usercontrol_1
from my calendar form but it does not show any of my shared controls or properties. I've tried Me.Parent.Controls
in a For Each loop. It found the controls but said I needed to use the New keyword. I tried new and it didn't work. Maybe I misunderstood what the intellisence was talking about.
Thanks in advance for your time and help.
At design time you cannot click a button which opens another form. Therefore I am really not sure what you are trying to achieve at design time.
I don't know the calender control you are using. Therefore I going to explain a possible solution using a DateTimePicker
. On the calender form (let's call it fdlgCalender
add a property that allows accessing the selected date of the calender control publicly:
Public Property SelectedDate() As Date
Get
Return DateTimePicker1.Value
End Get
Set(ByVal value As Date)
DateTimePicker1.Value = value
End Set
End Property
On your UserControl
containing the calender button, create a similar property. This time we are using a nullable date in order to indicate the situation where no date has been selected
Public Property SelectedDate As Date?
Now you can call the calender form like this:
Dim fdlg As New fdlgCalender()
If SelectedDate.HasValue Then
fdlg.SelectedDate = SelectedDate.Value
Else
fdlg.SelectedDate = Today
End If
' Assuming that the dialog form sets the `DialogResult` correctly
If fdlg.ShowDialog() = DialogResult.OK Then
SelectedDate = fdlg.SelectedDate
Else
SelectedDate = Nothing
End If
Now you can access the date from outside of your user control through the SelectedDate
property.
(The code is not tested)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.