|
I have looked on google and I can't find anything that does what I need in an example..
I want to validate the textbox on keypress and make it where the user(me) can't enter anything other than a price value. like 1.99 2.99 whatever..
I have it working so far as to only allow numbers a backspace and the '.' but I can't figure out how to restrict it to only 2 places after the decimal. Any help would be great. thanks..
Here is what I have so far...
private void Price_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !Char.IsNumber(e.KeyChar) && (e.KeyChar != '\b')&& (e.KeyChar != '.');
}
|
|
|
|
|
Use a NumericUpDown instead. It accepts only numeric input and you can specify in the designer how many decimal places it should use - no custom coding necessary.
|
|
|
|
|
Not quite, you can enter more decimals, its only when you Leave the Control that it gets rounded to the specified number of decimals.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
as Jimmanuel said you could use the numeric... But I have found some small
bugs in the numeric up down such: as you introduce some number then delete it and
if you get the .Value it's not null or zero or...
So, I had this problem too. Sorry I can find the code right now nor the time to write it but this is how you could do it:
use the KeyDown event and then put the logic:
e.Handled=true;
e.SuppressKeyPress=true;
use
e.KeyCode == Keys.OemPeriod to check for '.'
hope it helps
|
|
|
|
|
just checking the latest keystroke as if it comes at the right of what is already there isn't sufficient:
1. the caret might not be at the end
2. you may want to support: copy, cut, paste, backspace...
all of these require more than just checking the new character.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
true.
but I checked for stuff like that(if it's the delete key, back key etc)
As for the position of the caret/cursor I didn't really cared cause I transformed .8686 in
0.8686
It really works for me. What I said here/before are some "guide lines".
Again sorry I can't find the code. Just the *.dll.
Thanks for the correction. I mean it.
It should help TonyOnLinux too if he decides to implement
he's own logic/control.
|
|
|
|
|
A while ago I wrote this article[^] for a simple numeric text box. It would need some alteration to allow a decimal point and to check the number is valid for your requirements (at the moment it only allows numeric input i.e. it is still a text box and not a NumberBox) but it could serve as a starting point. It handles copy and paste via keyboard/mouse and all edit keys etc...
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Why not using a ConvertEventHandler delegate ?
|
|
|
|
|
You need only to check the text of textbox. My textbox is name tAmount
private void tAmount_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0;
Update();
string tmp = Convert.ToString(tAmount.Text);
if (tmp.Contains(".") == true)
e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber) && (e.KeyChar != '\b');
else
e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber) && (e.KeyChar != '\b') && (e.KeyChar != '.');
}
|
|
|
|
|
Hi
I need to know how to get notified whenever the createDCW() in gdi32.dll is called from other applications. i want to insert data between each startpage and endpage.
Please help!!
Thanks in advance
|
|
|
|
|
There's no such thing as "hooking" that call. Hooking refers to an entire differect concept in Windows.
You actually have to redirect the call, using a library called "Detours[^]" from Microsoft Research. You can read more on the technique here[^] and here[^]. Oh, and you can't do it in managed code, i.e. C# or VB.NET.
|
|
|
|
|
OK. So I'm trying to inherit from the ComboBox control (desktop) to make a custom time picker based on some unknown interval of time units. Every time the Increment (meaning interval) property is updated, therefore, the list of items needs to be repopulated. The Increment property can also be set using the designer. My item population code is set in a private method:
private void RepopulateChoices()
{
Items.Clear();
int i = 0;
while (i < 1440)
{
DateTime dat = new DateTime(1, 1, 1, i / 60, i % 60, 0);
if (ShowMilitary)
Items.Add(dat.ToString("HH:mm"));
else
Items.Add(dat.ToString("h:mm tt"));
i += Increment;
}
}
You can see the very first thing I do is clear the existing items from the control. I then iterate through 1440 minutes in a day, incrementing in "Increment" number of minutes.
With a default Increment of 30, there should be 48 items in the final list. However, I always see more than 48, and the number increases for every nested container. I.e., after "11:30 PM" comes another entry of "12:00 AM" and the cycle starts all over again.
dropped directly on a form: 96 items (2 days' worth)
dropped into a panel on a form: 192 items (4 days' worth)
dropped into a panel in a TableLayout container on a form: 284 items (6 days' worth)
WHAT THE HECK IS GOING ON HERE?
I have ruled out accidental population routines in the primary app because I can duplicate the behavior dropping this control onto a form in the app where no instance of the control already exists.
The RepopulateChoices() method is the ONLY place where I am populating items. Since that method starts with an Items.Clear() instruction, how on earth can I be getting massive quantities of duplicate entries???
|
|
|
|
|
You example works on my side:
Try this with TimeSpan, this may be due to local settings (culture)
int Elapse = 30;
comboBox1.Items.Clear();
int i = 0;
DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse("00:00:00"), DateTimeKind.Local);
while (i < 1440)
{
convertedDate = convertedDate + new TimeSpan(0, Elapse, 0);
if (ShowMilitary)
comboBox1.Items.Add(convertedDate.ToString("HH:mm"));
else
comboBox1.Items.Add(convertedDate.ToString("h:mm tt"));
i += Elapse;
}
|
|
|
|
|
Not sure why that would make a difference. I also noticed a syntax difference between your code and my code:
Migounette wrote: comboBox1.Items.Clear();
I did not use a designer to make a custom control. I inherited directly from ComboBox. I call Items.Clear() from RepopulateChoices(), which is a private method in the inherited class. All of your code starting with "comboBox1..." is not at all how I'm doing things.
I'm going to make another post to clarify as there seems to be a tremendous amount of confusion over this from all respondants.
|
|
|
|
|
Xpnctoc wrote:
private void RepopulateChoices()
{
Items.Clear();
What is Items???
It should be something like
this.myComboCtrl1.Items.Clear(); or without the this.
Who calls the RepopulateChoises method??
Elaborate.
|
|
|
|
|
I found this code, that should validate an Email address according to the RFC2822.
Now im not the big regex user so i would like it if someone could verify this for me.
^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$
Thanks..
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
You might want to read this[^] page on validating email addresses. It's very enlightening, and should go a long way to answering your question (pay attention to items such as international email addresses).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete, will do...
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
Good evening,
I am trying to work out if it is possible to work out which DLL the RunDLL32.exe process is "running" through C# (or C++)
Any help/guidance would be sincerely appreciated
|
|
|
|
|
|
The Modules list doesn't actually contain the dll that's loaded by rundll32. You need to do extra work to get that information.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You can do this with WMI. Here's a sample combining the Process and ManagementObject classes to show some useful info:
string process = "SELECT CommandLine FROM Win32_Process WHERE ProcessID = {0}";
foreach (Process p in Process.GetProcessesByName("rundll32"))
{
using (ManagementObjectSearcher mos = new ManagementObjectSearcher(string.Format(process, p.Id)))
{
foreach (ManagementObject mo in mos.Get())
{
string[] commandLine = mo["CommandLine"].ToString().Split(',');
Console.WriteLine(string.Format("{0} was started at {1}.",
commandLine[0].Substring(commandLine[0].IndexOf(" ") + 1), p.StartTime));
}
}
} There's a whole hunk of substringing going on with the command line to get the DLL because the command line would be Rundll32.exe c:\PathToMyDll\MyDll.dll,Entrypoint so we need to parse it out.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks very much, this works and works well!
|
|
|
|
|
|
Kindly check the below program.
using System;
namespsace TestException3
{
Class program
{
static void Main(string args[])
{
try
{
string s1,s2,ans;
char type,type1;
Console.WriteLine("please enter the variables : ");
s1=Console.ReadLine();
s2=Console.ReadLine();
type=Convert.ToChar(s1);
type1=Convert.ToChar(s2);
if(!(char.IsDigit(type)) || !(char.IsDigit(type1)))
{
throw new Exception("Please Enter numbers only");
}
else
{
ans=Convert.ToString(Convert.ToInt32(s1)+Convert.ToInt32(s2));
Console.WriteLine(Answer : {0}",ans);
Console.ReadLine();
}
catch(Exception e)
{
Console.WriteLine("Message : {0}", e.Message);
Console.ReadLine();
}
}
}
}
|
|
|
|