在我的windows窗体中,我添加了一个用于输入新记录的按钮,当该按钮被选中时,按钮文本将变为取消,焦点将移动到第一个输入字段。但是如果我在没有输入任何数据的情况下单击cancel,当我按下next record时,焦点不会被移除,那么焦点就会被移除&我可以再次按add .and record按钮。请帮助我如何解决这个.below是我的代码
Private Sub AddnewButton_Click(sender As Object, e As EventArgs) Handles AddnewButton.Click
'MsgBox("you preseed add new button")
Try
With AddnewButton
If .Text = "Add New Record" Then
MSdiesBindingSource.AddNew()
.Text = "Cancel"
Else
RefreshData()
.Text = "Add New Record"
End If
End With
With Size_in_mgTextBox
If (.CanSelect) Then
.Text = String.Empty
.Select()
End If
End With
IsAddNewRecordInProgress = Convert.ToBoolean(AddnewButton.Text = "Cancel")
Catch ex As Exception
MsgBox("An error occured: " & ex.Message.ToString().ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Add new Record Failed")
End Try
End Sub
Private Sub RefreshData()
Try
'Me.MSdiesBindingSource.Filter = Nothing
MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
MSdiesBindingSource.RemoveFilter()
Catch ex As Exception
MsgBox("Refresh Data Error!")
End Try
End Sub

SELECT ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns],[Condition of DIE-1], [Condition of DIE-2], [Condition of DIE-3], [Condition of DIE-4], [Condition of DIE-5],[Condition of DIE-6],[Condition of DIE-7], Observations, Inspector来自MSdies

发布于 2020-07-23 16:15:56
But if i click cancel without entering any data , the focus is not getting removed为了从'Size_ In _mgTextBox‘中移除焦点,你可以对你的代码做一些修改:
With Size_in_mgTextBox
If (.CanSelect) Then
.Select()
End If
End With
With AddnewButton
If .Text = "Add New Record" Then
bindingSource.AddNew()
.Text = "Cancel"
Else
RefreshData()
.Text = "Add New Record"
End If
End With
Size_in_mgTextBox.Text = String.Empty然后将以下代码添加到“RefreshData”方法中:Me.ActiveControl = Nothing
Private Sub RefreshData()
If Size_in_mgTextBox.Text.Trim = "" Then
Me.ActiveControl = Nothing
Else
'...
End If
End Subhttps://stackoverflow.com/questions/62991536
复制相似问题