Return 值到新表格调用的文本框

Return value to the text box where the new form called

在我名为 'authors' 的表单中,我有两个文本字段,它们都用于获取两个不同的日期作为输入。如果用户聚焦文本框,它将显示我以其他形式放置的日历。 select输入日期并单击 select 按钮后,select输入的日期将分配给文本框。

这是我写的代码:

作者-编码:

Private Sub DOFE_TextChanged(ByVal sender As System.Object, ByVal e As      System.EventArgs) Handles DOFE.GotFocus
If DOFE.Text = "" Then
        Calendar.ShowDialog()
    Else
        Me.DOFE.Select()
        Me.DOFE.Focus()
    End If
End Sub

日历-编码:

Private Sub B_SELECT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_SELECT.Click
    Authors.DOFE.Text = Format(MonthCalendar1.SelectionRange.Start(), "dd/MM/yyyy")
    Me.Close()
End Sub

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
    Authors.DOFE.Text = Format(MonthCalendar1.SelectionRange.Start(), "dd/MM/yyyy")
End Sub

现在的问题是,当我尝试执行以下代码时:

Private Sub DOB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DOB.GotFocus
    If DOB.Text = "" Then
        Calendar.ShowDialog()
    Else
        Me.DOB.Select()
        Me.DOB.Focus()
    End If
End Sub

我的意思是,此代码用于将其他日期分配给相同形式的其他文本字段。

添加单行是可能的

**Authors.DOB.Text** = Format(MonthCalendar1.SelectionRange.Start(), "dd/MM/yyyy")

以日历形式,但两个文本字段都会发生反射。

在这方面给我建议。

一种方法是使用 Public 变量来保存日期,然后在 ShowDialog 方法之后分配它。

所以在某些模块中你会

Public tempDate As Date

在您的日历代码中

Private Sub B_SELECT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_SELECT.Click
    tempDate = Format(MonthCalendar1.SelectionRange.Start(), "dd/MM/yyyy")
    Me.Close()
End Sub

然后在您的 Text_Changed 活动中

Private Sub DOB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DOB.GotFocus
    If DOB.Text = "" Then
        tempDate = ""
        Calendar.ShowDialog()
        DOB.Text = tempDate
    Else
        Me.DOB.Select()
        Me.DOB.Focus()
    End If
End Sub