Click here to Skip to main content
13,044,115 members (82,293 online)
Rate this:
Please Sign up or sign in to vote.
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
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
            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 21-Mar-13 16:25pm
Updated 21-Mar-13 17:11pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100