0
我正在为Autodesk Inventor(3D绘图软件)创建AddIn,并且目前我正在玩位置约束。输入按钮被按下时验证文本框
我创建了一个自定义用户菜单,用于快速编辑某些值,在本例中为高程和方向值。
首先我使用textbox.textchanged
事件来更改我的约束值。但这不是100%。按下高程1000时的示例会更改高程4次(每位数字)。
现在我去了使用validated event
。这效果更好,但我想要按下Enter
按钮时,文本框启动验证。为此我鞭打了这一点,但我确信它不正确。我应该如何正确写入?
下面的代码工作,但我想有一个正确的方法来实现结果。
Private Sub tbElevationValue_TextChanged(sender As Object, e As EventArgs) _
Handles tbElevation.Validated
' If the elevation parameter and textbox value are the same
' The sub must be aborted
If CDbl(tbElevation.Text) = oElevationParameter.Value * 10 Then Exit Sub
' Check the entered value
Dim oValue As Double
If tbElevation.Text = "" Then
oValue = 0
tbElevation.Text = 0
Else
oValue = tbElevation.Text
End If
' Set the parameter value
oElevationParameter.Value = oValue/10
' Update the document
EM_AddIn.StandardAddInServer.m_inventorApplication.ActiveDocument.Update()
End Sub
Private Sub tbOrientation_TextChanged(sender As Object, e As EventArgs) _
Handles tbOrientation.Validated
' If the orientation parameter and textbox value are the same
' The sub must be aborted
If CDbl(tbOrientation.Text) = cRandiansToDegrees(oOrientationParameter.Value) Then Exit Sub
' Check the entered value
Dim oValue As Double
If tbOrientation.Text = "" Then
oValue = 0
tbOrientation.Text = 0
Else
oValue = tbOrientation.Text
End If
' Set the parameter value
oOrientationParameter.Value = cDegreesToRandians(oValue)
' Update the document
EM_AddIn.StandardAddInServer.m_inventorApplication.ActiveDocument.Update()
End Sub
Private Sub OrientationElevationEnterKey_Pressed(sender As Object, e As Windows.Forms.KeyEventArgs) Handles tbElevation.KeyUp, tbOrientation.KeyUp
If e.KeyCode = Windows.Forms.Keys.Enter Then
CType(sender, Windows.Forms.TextBox).Parent.Focus()
CType(sender, Windows.Forms.TextBox).Focus()
End If
End Sub
这样不是会导致每一次击键制成,即使它不是在'文本boxes'我要监控的事件,该事件被触发?这是否会消耗比所需资源更多的资源? –
确实如此,但您可以轻松地在KeyDown事件中添加测试,以便仅在当前的焦点控件是文本框 – theBugger