473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Customized IntegerTextBox problem

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
Nov 20 '05 #1
3 1152
Do you mean something along the lines of Me.Focus() ??

~Brian

"Christian Soltenborn" <no*****************@web.de> wrote in message
news:c5************@ID-36219.news.uni-berlin.de...
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

Nov 20 '05 #2
"Christian Soltenborn" <no*****************@web.de> wrote in message
news:c5************@ID-36219.news.uni-berlin.de...
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?
Overriding OnValidating or OnValidated sounds like what you want.
OnValidating is most likely better, since it gives you the option of
stopping the control from losing focus if the input is invalid.

Also, be sure to call the base class method somewhere in there. In your
code, I notice there is no call to MyBase.OnTextChanged(e) in there
anywhere.
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.


Me.Focus = True

My gut reaction is also that setting the focus should be a method and
not a property, but what can you do?

Jeremy

Nov 20 '05 #3

"Jeremy Todd" <jh****@uiuc.edu> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
"Christian Soltenborn" <no*****************@web.de> wrote in message
news:c5************@ID-36219.news.uni-berlin.de... Me.Focus = True

My gut reaction is also that setting the focus should be a method and
not a property, but what can you do?


Er, I had a brain shutdown or something. "Focus" -is- a method, not a
property. "Focused" is the property, and it's read-only. Sorry for giving
bad advice!

Jeremy

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shovan | last post by:
I am creating a customized Purchase order report using asp. I have developed the reoprt as it is displaying the amount against a sales rep within a specific date range.now values are dispalaying...
1
by: Paiam Salavati | last post by:
I want to change the the color of the tabs and the color of TabControl itself in a TabControl. Therefore I wrote the following code in my customized TabControl-class: this.DrawMode =...
1
by: Jean Bredeche | last post by:
Hi: I am trying to create customized confirmation/error/etc dialogs in my application. Up to now we've been using MessageBox.Show and passing it the various necessary flags (buttons, icons,...
0
by: Chris | last post by:
To centralize much of the database connectivity and variable declarations, I decided it would make sense to create my own class that inherits from the page class and derive each of my form classes...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
0
by: segal.aviad | last post by:
Hi, I'm trying to create a customized setup project for my application. I want to write a setup project which will install several merge modules (- this I know how to do). Before running the...
5
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to...
7
by: SteveT | last post by:
I would like to create a customized DataGridViewColumn called DataGridViewCheckedListBoxColumn. I'd like the ability to multi-select items in the list. Does anyone know of an example of how this...
6
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.