[英]Referencing UserControl's constituent TextBox from another form at design time vb.net
Right up front, I'm writing in vb code, not c#. 就在前面,我是用vb代码而不是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.
我是vb.net的新手。 (come from vb6)
(来自vb6)
I'm creating a user control_1
which contains textboxes and a button. 我正在创建一个用户
control_1
,其中包含文本框和一个按钮。 Control_1
inherits from another user control_2
(a few textboxes and the calendar form button). Control_1
继承自另一个用户control_2
(一些文本框和日历表单按钮)。 When I press the button it launches a Calendar form containing a CalendarControl
. 当我按下按钮时,它将启动一个包含
CalendarControl
的Calendar表单。
Works fine so far. 到目前为止工作正常。
Now I need to return the CalendarControl
value on it's Calendar form back to the unseated user control_1
. 现在,我需要将其Calendar窗体上的
CalendarControl
值返回给未安装的用户control_1
。 I am talking design time here, User Control_1
is not seated on a form yet. 我在这里说的是设计时间,用户
Control_1
尚未坐在表单上。
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. 我尝试从日历表单中调用
Usercontrol_1
,但它不显示任何共享控件或属性。 I've tried Me.Parent.Controls
in a For Each loop. 我已经在For Each循环中尝试过
Me.Parent.Controls
。 It found the controls but said I needed to use the New keyword. 它找到了控件,但说我需要使用New关键字。 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
. 因此,我将解释使用
DateTimePicker
的可能解决方案。 On the calender form (let's call it fdlgCalender
add a property that allows accessing the selected date of the calender control publicly: 在日历表单上(我们将其
fdlgCalender
添加一个属性,该属性允许公开访问日历控件的选定日期:
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. 在包含压延按钮的
UserControl
,创建一个类似的属性。 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. 现在,您可以通过
SelectedDate
属性从用户控件外部访问日期。
(The code is not tested) (该代码未经测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.