Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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


but nothing is calculating in its lostfocus
Posted
Updated 21-Mar-13 17:11pm
v2

1 solution

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)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900