没有从我的UserControl获取值 [英] Not getting the Value from my UserControl
本文介绍了没有从我的UserControl获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个用户控件,只接受数字数字。
我在表单上使用此控件计算总共2个数字
我在两个控件中输入了一些值。只有值显示在用户控件中(例如10,20)
但我没有得到总数。我把BreakPoint放在了LostFocus活动中。
但它并没有参加那个特定的活动。为什么&怎么做。
i在我的usercontrol中写了以下代码
i created a user control to accept only Numerical Digits.
I used this control on my form to calculate total of 2 numbers
i entered some values in both controls. only values are showing in user controls (ex 10, 20)
but iam not getting the total. and i put BreakPoint in LostFocus event.
but it is not comming to that particular event. why & what to do.
i had written the following code in my usercontrol
Public Class Number2
Public Event TxtN_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Private Sub txtN_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtN.KeyPress
If e.KeyChar <> "." And (e.KeyChar < "0" Or e.KeyChar > "9") Then
e.Handled = True
End If
End Sub
Private Sub txtN_LostFocus1(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtN.LostFocus
txtN.Text = FormatNumber(Val(txtN.Text), 2, , , False)
End Sub
Private Sub txtN_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtN.TextChanged
RaiseEvent TxtN_TextChanged(sender, e)
End Sub
Property txtNtext() As String
Get
txtNtext = txtN.Text
End Get
Set(ByVal value As String)
txtN.Text = value
End Set
End Property
End Class
and in form i am using it as
Private Sub txtN1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtN1.LostFocus
txtN3.Text = FormatNumber(Val(txtN1.Text) + Val(txtN2.Text), 3, , , TriState.False)
End Sub
但是没有任何东西在计算它的lostfocus
but nothing is calculating in its lostfocus
推荐答案
你好,看起来你可以做几件事。将用户控件重构为从TextBox继承并覆盖标准事件...或者将TxtN_LostFocus的事件添加到Number2类,并从txtN_LostFocus1方法引发该事件,就像使用TxtN_TextChanged事件和txtN_TextChanged_1方法一样。
此外,对于自定义事件,使用On [事件名称]是标准的。 (例如:OnLostFocus,OnTextChanged)
Hello, looks like you could do a couple things. Restructure the user control to Inherit from TextBox and override the standard events... or add an Event for TxtN_LostFocus to your Number2 class and raise that event from the txtN_LostFocus1 method like you are with the TxtN_TextChanged event and txtN_TextChanged_1 method.
Also, with custom events it is standard to use On[Event name]. (ex: OnLostFocus, OnTextChanged)
这篇关于没有从我的UserControl获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文