Nasao sam ovaj kod koji je za C
foreach (Control c in MyControls.Controls)
{
if (c.GetType().FullName == "System.Windows.Forms.TextBox")
{
TextBox textBoxControl = (TextBox)c;
textBoxControl.Leave += new EventHandler(textBoxControl_Leave);
}
}
private void textBoxControl_Leave(object sender, EventArgs e)
{
decimal broj;
TextBox myTb = (TextBox)sender;
if (decimal.TryParse(myTb.Text, out broj))
{
myTb.Text = broj.ToString("N2");
}
}
Preveo sam ga u VB i dobio ovako nesto:
For Each c As Control In MyBase.Controls
If c.[GetType]().FullName = "System.Windows.Forms.TextBox" Then
Dim textBoxControl As TextBox = DirectCast(c, TextBox)
textBoxControl.Leave += New EventHandler(textBoxControl_Leave)
End If
Next
Private Sub textBoxControl_Leave(ByVal sender As Object, ByVal e As EventArgs)
Dim broj As Decimal
Dim myTb As TextBox = DirectCast(sender, TextBox)
If Decimal.TryParse(myTb.Text, broj) Then
myTb.Text = broj.ToString("N2")
End If
End Sub
Ali imam problema sa redom textBoxControl.Leave += New EventHandler(textBoxControl_Leave) i dobijem sledecu gresku:
Public Event Leave(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.