C
Christian Soltenborn
Hi,
I would like to have some customized TextBoxes, e.g. like this:
Public Class IntegerTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
Try
Integer.Parse(Me.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number!")
End Try
End Sub
End Class
For this, I have two questions:
a) If I override onTextChanged(), the method is called for every char
entered. This would actually work for integers, but not for more complex
data like a TimeSpan. Therefore I would like to override a method which
is called if the complete data is entered (e.g. if the text box looses
focus). Is there a way to do this?
b) I also could not figure out how I can give the focus back to my
object after displaying the MessageBox. I didn't see anything like
Me.SetFocus(), I can just ask if I have focus.
Thanks,
Christian
I would like to have some customized TextBoxes, e.g. like this:
Public Class IntegerTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
Try
Integer.Parse(Me.Text)
Catch ex As Exception
MessageBox.Show("Please enter a valid number!")
End Try
End Sub
End Class
For this, I have two questions:
a) If I override onTextChanged(), the method is called for every char
entered. This would actually work for integers, but not for more complex
data like a TimeSpan. Therefore I would like to override a method which
is called if the complete data is entered (e.g. if the text box looses
focus). Is there a way to do this?
b) I also could not figure out how I can give the focus back to my
object after displaying the MessageBox. I didn't see anything like
Me.SetFocus(), I can just ask if I have focus.
Thanks,
Christian