Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB8.0
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
 
but nothing is calculating in its lostfocus
Posted 21-Mar-13 17:25pm
Edited 21-Mar-13 18:11pm
_Maxxx_110.7K
v2

1 solution

Rate this: bad
good
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)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2014
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