|
I have two text boxes which i want to validate
First TextBox:
Only Allow an integer as input, Check If it is not then make it an integer and put out a warning msgbox that it has been changed.
Second TextBox:
Only Allow allow a decimal number (with 1 decimal point only).
So if it is has two decimal places then trim it down to one and put out a warning.
Hope I have made my self clear
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
|
|
|
|
|
on the first you can write something like that:
try{
int.Pars(TextBox.Text);
catch(){
//if it is not a number
}
On the other you can make the same and than check if the Number div 10 == 0;
Then you should have just one decimal point.
I hope that works, don´t know the exceptoion Type that is thrown if its not a number
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
Fatbuddha 1 wrote: try{
int.Pars(TextBox.Text);
catch(){
//if it is not a number
}
There is int.TryParse() for this scenario.
Fatbuddha 1 wrote: don´t know the exceptoion Type that is thrown if its not a number
FormatException
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
dnh wrote: There is int.TryParse() for this scenario.
Only in .Net>1.1
But in this case I would use double.TryParse, with System.Globalization.NumberStyles.Integer as param.
|
|
|
|
|
True, OP doesn't specify which version of framework he uses. If it is 1.x then indeed your approarch seems to be best
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Thank you!
|
|
|
|
|
Sorry for tha. I just came for a month from Java programming to C#.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
I hope this helps...
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
try
{
int intValue = int.Parse(textBox1.Text);
}
catch (FormatException)
{
MessageBox.Show(textBox1.Text + " is not an integer");
}
}
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
try
{
decimal decValue = decimal.Parse(textBox2.Text);
string dec = decValue.ToString();
int i = dec.IndexOf(".");
if (dec.Length > (i + 1))
{
dec = dec.Substring(0, (i + 2));
throw new Exception("You value of " + textBox2.Text + " has too many numbers following the decimal point. You're new value is " + dec);
decValue = decimal.Parse(dec);
textBox2.Text = dec;
}
}
catch (FormatException)
{
MessageBox.Show(textBox1.Text + " is not an integer");
}
}
Lester
http://www.lestersconyers.com
|
|
|
|
|
If it is WinForms, use MaskedTextBox[^], if it is ASP.NET web app, use RegularExpressionValidator [^] or maybe RangeValidator[^].
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Hello all,
Does anyone know of an application that can take an XML file and generate a class structure for reading and writing it? I just need something very simple, just to get started.
|
|
|
|
|
|
I did find this. Hopefully it will do what I need:
http://marcclifton.com/tabid/93/Default.aspx
|
|
|
|
|
Hi All,
One section of my app involves drawing multi point lines over the top of an image. The image scrolls.
I have internally a list of (world) coordinates, and in every OnPaint handler i'm recalculating the screen coordinates that these correspond to, so that I have a Point[] array, which can be used in Graphics.DrawLines
Problem is that the coordinate calculations are rather slow, and profiling the code shows quite a chunk of time wasted in this part of the app.
I can precalculate the coordinates, but they will still need translating as the image is drawn because it scrolls. But this translation would be simple, because it's just linear.
Does anyone know of an optimised way of translating a large set of coordinates? Or will i just need to loop around my list and do it that way?
Thanks
Jon
|
|
|
|
|
Hi Jon,
the easiest approach would be to rely on Graphics.TranslateTransform(); this will
cause the calculations to occur everytime OnPaint runs, but they will happen in the
most optimized way Microsoft has implemented in Graphics.
One way to speed up things even more is to somehow avoid painting stuff that will
be clipped away due to the scrolling; this requires you keeping all your stuff
in an ordered fashion so you can skip those parts that fall definitely above
the currently visible part, as well as those parts that definitely fall below it.
Of course these decisions could be based on world coordinates.
Depending on the dynamics of your app, you may also consider drawing the image
and all the lines once in an off-screen buffer (Bitmap), and show only the
relevant parts as needed.
Hope this helps.
|
|
|
|
|
Hi Luc,
Thanks for the comments.
TranslateTransform looks like it's going to be really helpful, I shall experiment and see if it makes some performance gains.
I already only draw approximately what is needed. I simplified a little in my post - the image is actually a grid of image tiles, which are usually in the region of 150px by 150px. Each image tile has it's own list of coordinates which are on top of it, which are calculated at the start. I have logic to tell which tiles are in view in any given OnPaint call, so I only do extra line drawing where a tile is clipped by the edge of the window.
Thanks
Jon
|
|
|
|
|
Hi Friends,
I am using asp.net with c#.I am new to Chain Verification Process.i need to verify client certificate with root certificate of the server .in that i was struck with verifing the publickey.i am able to dispaly the Thumbprint and publickey of the certificates but i am unable to verify that Thumbprint and publickey.
It is greatful to give an example which is help to me
Cheers,
Happy Coding
|
|
|
|
|
Hello everyone.
I’m .NET developer (VB.NET). At the company I work I use VS 2003 and .NET Framework 1.1 to develop different tools (web based and windows based) to replace some of the process in my company, basically make some tasks easy to do.
My company is evaluating SharePoint Server 2007 (MOSS) to get us company Intranet and of course use document management and other collaboration tools that SharePoint has to offer. Of course I will be programming in C# and that’s why I’m in the middle of adapting to the new language.
Did anyone have any experience with SharePoint development and/or customization? I would like to get any information as I can get: links to the sites, books, etc. Basically anything that can help me to get started. Please consider me as new user and I know nothing about it. Where do I start (especially development for SharePoint)?
I found the following books at Amazon.com. Do you think these would be enough or I will need anything else?
http://www.amazon.ca/Professional-SharePoint-2007-Development-Holliday/dp/0470117567/ref=pd_sim_b_3/701-8834183-4638738?ie=UTF8&qid=1181779059&sr=8-1
http://www.amazon.ca/Beginning-SharePoint-2007-Building-Solutions/dp/0470124490/ref=pd_sim_b_3/702-7805079-5962455?ie=UTF8&qid=1181779059&sr=8-1
Thank you very much for your help.
|
|
|
|
|
I have a program where i need to display an image in a picturebox & have users be able to select a part of the image for printing. I haven't be able to find any method of accomplishing this. I've tried drawing a rectangle on the image but drawing and re-drawing the image take far too long (these are very large images).
Any ideas/links?
Thanks
R.Myers
|
|
|
|
|
It is obvious to use rectangle to allow user to draw from source x,y coordinate to destination x,y coord. BitBlt()(Bitmap Block Transfer) available in VC would help to do ur task easily.
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
Thanks for the response. Do you (or anyone else) know of a newbie-type guide to using BitBlt? I've been looking, but i haven't found anything.
Thanks again
R.Myers
|
|
|
|
|
Hello,
If the listview control is populated with items, and user preses for example key "r", the list view control scrolls to the first object in the listview control whose text starts with letter "r". How can I achive this programatically? Meaning, if I have a button, and when user presses the button, it sends a key stroke event to listview control with letter "r".
Thank you.
|
|
|
|
|
Something like this:
private void listView1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.R)
{
//search the list view for item
listView1.Items[0].Selected = true;
}
}
|
|
|
|
|
Thanks.
But ListView control already has a default behaviour for the key strokes. I was just wondering if I can use API SendMessage somehow to emulate this default behaviour.
|
|
|
|
|
Hello
I am sharing a folder through sharing property. For that, i just right click on the folder and shared it...Now i can easily access this folder from any computer within a network. This is so simple.
Now i have done the same job through C# code. It works properly. But when i access this folder from any computer, it shows an error i.e. access denied.
I am not able to understand the reason.
Plz reply me asap.
Thanks
Devesh Mishra
|
|
|
|
|
I am not sure if that is the problem, but you did not mention security in your post. When you share a folder and you want anyone to access it you need to give permission. Have you done that in your code?
|
|
|
|