|
Basic validation is done using the Validating and Validated events; however you probably want to stop the user from entering any text at all.
If you inherit from the TextBox class, you can intercept the OnKey* events to stop non-numbers from being entered in.
James
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
yes, and you can use the ErrorProvider component to give the user a good reason as to why it's wrong.
|
|
|
|
|
Ok, I am going to say no you Can't intercept the Text in the *OnKey* events unless you give me a sample. I have been trying to stop text being entered for days now and I am about to write a Custom handler using the WndProc function.
Basically, the OnKey events don't work. I've set "e.Handled = True" and I've even tried not passing the Argument to the Base Class. Nothing works and whatever Text the user enters goes into the TextBox!
|
|
|
|
|
Something like this perhaps?
protected override void OnKeyPress(KeyPressEventArgs e)
{
const char Delete = (char) (int) Keys.Delete;
const char Backspace = (char) 8;
char key = e.KeyChar;
string strKey = key.ToString();
System.Globalization.NumberFormatInfo nfi =
System.Globalization.NumberFormatInfo.CurrentInfo;
e.Handled = true;
if( key == Delete || key == Backspace )
e.Handled = false;
if( char.IsDigit(key) )
e.Handled = false;
if( nfi.NumberDecimalSeparator == strKey )
{
if( Text.IndexOf(nfi.NumberDecimalSeparator) == -1 )
e.Handled = false;
}
if( nfi.NegativeSign == strKey )
{
int selStart = SelectionStart;
int selLength = SelectionLength;
if( Text.IndexOf(nfi.NegativeSign) == -1 )
{
Text = nfi.NegativeSign + Text;
SelectionStart = selStart + nfi.NegativeSign.Length;
SelectionLength = selLength;
}
else
{
Text = Text.Remove(0, nfi.NegativeSign.Length);
if( selStart == 0 )
{
selLength -= nfi.NegativeSign.Length;
SelectionStart = 0;
SelectionLength = selLength;
}
else
{
SelectionStart = selStart -
nfi.NegativeSign.Length;
SelectionLength = selLength;
}
}
}
base.OnKeyPress(e);
} Usage: - Create a class that inherits from
System.Windows.Forms.TextBox - Add above method to it
- Use in application
HTH,
James
- out of order -
|
|
|
|
|
I am a Senior Developer who has recently been caught up with .NET euphoria.
I am about to write a web based application for Administering IIS Properties like
1) create domains
2) change metabase properties etc just like ISM.
I know how to do this using VBScript or ASP for that matter.
However we want to implement this as .NET application in C# or vb.net or asp.net
I know java(100%), c# ( just started) , VBSctips (good enough), c++ (100%)
Can somebody suggest which would be a better choice for me keeping in mind the following points
1) I do care about performance. I change one check box in IIS properties and save. This should not take irritatingly long time.
This application will be used by many people simultaneously on a windows server. Te most frequent operation will be changing metabase properties.
2) I need to access the following Windows stuff
a) windows users/groups
b) registry ( i can use VBScript if I want to enumerate registry)
c) File System files
3) This application is to be accessed by a known set of people with login/password
Should I use SOAP/XML stuff as well or do I make is a Simple WebApplication
Any Suggestions?
Swarup Das
|
|
|
|
|
|
is there a way to do this? i need a rectangle with rounded corners, but it also needs to be filled in. Help me plz.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
I have an article on CP showing how to do this with GDI+.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
|
|
Hi everyone,
I come mainly from a C++ background. However, I am very interesting in learning C#. I am particularly interested in developing my own GUI controls (seems easier to do it than C++). I am also proficient in Java. Can somebody point me to some tutorials or code samples that can help me? Codes for control subclassing or creating controls and registering them with the designer and stuff would be great!
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Codeproject has quite a big selection of articles and tutorials that should get u going in no time
Just look under the C# section.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
im interested too, in fact, i started making one about 4 days ago, its a good way to learn [i think] because if forces you to exlplor features.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
|
Hi, did a quick search on MSDN, not sure if this is what you are looking for but mite help .
Graphics.MeasureString Method
Graphics Class | Graphics Members | System.Drawing Namespace
Measures the specified string when drawn with the specified Font object.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Say we have a list box and we have items. Now some of the items have long text, so that the entire text won't fit in [means we only see the left most portion that fully fits into the box].
Now we can show tool-tips and solve this issue. But what if I don't wanna show tool tips for those items that have text short enough to fit in the width of the listbox?
How do I determine whether a given string will fully fit into the listbox?
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
I have a question about OnMouseHover and OnMouseMove! They seem to be called together
For example I assume OnMouseHover gets called when the mouse stays at a point for some amt of time. But I find that it is called along with OnMouseMove
Can someone who has experiences some similar stuff care to explain this to me?
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
|
My findings:
1. MouseHover only gets called if control has focus.
2. MouseMove gets called regardless.
3. MouseMove gets called when mouse is clicked or control receives focus.
4. MouseHover gets called when mouse hasnt moved for an interval (time???).
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
|
|
|
Getting value from stuff you don't own is a compelling
idea. Just think, someone else has created something
that has value, and has made it available to you. You
can now leverage its value in ways that makes all
parties richer. That's the promise of web services.
You need to know about web services. The advent of
standards-based web services marks a new era of
system development. First mainframe, then client-server,
the Web, now web services makes it possible to leverage
every legacy system of the past and do so much more
with your information assets.
Architag Press, a division of Architag International
Corporation, announces the publication of Web Services
Implementation Guide, Volume 1: Getting Started, by
Brian E. Travis and Mae Ozkan.
Sample chapters of the book is available at
http://www.architag.com/press/wsig.
This book will show you what a web service is, and
how you can align your internal systems and external
trading partner interactions to take advantage of this
new concept in system integration.
You will learn about the "Three Steps to Web Services":
* Automate internal systems
* Determine integration points
* Expose integration points as web services
This book is for systems architects, developers,
and I.T. decision makers.
Highlights in this book:
* Written in a light, entertaining style.
* Emphasis on architectural design for web services.
* A tutorial on the state of web services standards.
* Plenty of real-life examples of web service use.
* Tutorials on the key technologies: XML, SOAP,
WSDL and UDDI.
* Code samples of key XML-based web services
technologies and extensions.
* Companion Web site with all code samples and
late-breaking information.
----
Download sample chapters of Web Services Implementation
Guide at http://www.architag.com/press/wsig/.
Stanford Powers, Publisher Architag International Corp
Phone: 866-898-0001 Outside US: +1-303-426-3126
Email: spowers@architag.com Fax: 720-294-1396
|
|
|
|