|
Hi there I have a textbox and want only numeric values to be entered because the value eneterd into the textbox will be written to my database. Thank you
|
|
|
|
|
Handle the KeyPress event and check the pressed key. If it doesn't fit your requirements discard it.
|
|
|
|
|
|
handle the keypress event and write the following code
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
|
|
|
|
|
Nouman Bhatti wrote: handle the keypress event and write the following code
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
Will not provide a copy paste functionality!
All the best,
Martin
|
|
|
|
|
Thanks for everyone who replied on my question. I cant get it right do you mean :
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
}
I have more than one textbox on that form so how do I check only one?
Thanks again.
|
|
|
|
|
Hello,
He meant you should inherit your own NumericTextBox (which has been done about 100 times in the articles)
from Forms.TextBox, and override the OnKeyPress method there.
Or handle the KeyPress event for only the textbox you like to modifie (Like Pete suggested)
yourTextBox.KeyPress+=new KeyPressEventHandler(...);
All the best,
Martin
|
|
|
|
|
It's been suggested to you that you should check the KeyPressEventArgs for the OnKeyPress handler. The code would look like this:
private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsNumber(e.KeyChar))
e.Handled = true;
} This basically uses the IsNumber member of the char type to determine whether or not a number was pressed. If the user types anything other than a number, the Handled value is set to true. This basically tells the system to ignore that keypress.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks again for replying. I still cant get it right this is the code I used I dont know what to do so I just tried this can you help me again please.
public class NumericTextBox : TextBox
{
private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsNumber(e.KeyChar))
e.Handled = true;
}
}
where must public class NumericTextBox : TextBox be inserted?
|
|
|
|
|
The code I presented was the event handler for a particular textbox (txtNumber). You would add this code by selecting the textbox in the designer, and then open up the Properties for it. Click the events icon (the one with a little lightning flash on it). And double click the KeyPress item in the property grid. Then you enter the if (...) code inside the auto-generated event handler.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Could anyone please tell me how to change the System.IO.Stream to System.Drawing.Icon?
Example ~
<br />
Dim asm As Assembly = Assembly.LoadFile(assemblyFile)<br />
Dim imgStream As Stream<br />
imgStream = asm.GetManifestResourceStream("MyDLL.MyIcon.ICO")<br />
<br />
Me.Icon = imgStream <<< ERROR: Need to convert the stream to icon...
Thanks in advance.
|
|
|
|
|
Hello,
The Icon class provides a constructor which takes a stream as param!
See the doku[^]
So in C# example:
Icon MyIcon = new Icon(yourStream);
All the best,
Martin
|
|
|
|
|
|
There is a constructor for Icon class which will accept Stream as parameter.
You should be able to do like this
Me.Icon = new Icon(imgStream);
*jaans
|
|
|
|
|
|
I reckon the Icon class might have a constructor which takes a stream.
[can I get my '5' now as well please!]
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
I give you mine for the funny idea!
All the best,
Martin
|
|
|
|
|
I gave my '5' to them for two reasons..
#1. the answer helps me a lot.. maybe.. the solution might be so easy or small but I don't know so it is helpful for me..
#2. they are watching codeproject forum all the time.. so I got the answer quickly...
|
|
|
|
|
I wasn't knocking you - honest!!;) It's good that people vote, and better when the answer voted for is quick, easy and importantly, correct.
I just think it is funny when two people post virtually the same answer to the question. I know it gives you, as the OP, more confidence the answer might be correct, but certain people (they know who they are!) do it just to get their post count up.
<edit>I'm digging a hole for myself now...I am not saying that J@@NS did this for the reasons above - the times are too close together. I think I better shut up whilst I am ahead, or at least not too far behind... lt;/edit>
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
Hi
I want to create treenode and save those node as an xml file can any one please help.
Mamphekgo
|
|
|
|
|
I am writing a program that consists of several applications, some are client applications, one is the master application, all are standard Windows Forms apps. The clients can all be started seperatly by the user, or the master application starts them automaticly to have the standard user interaction of the client programs and also automated interaction / control with the master program. I would like to do the interaction by simply using public methods and events.
My question is now how do I start the client applications automaticly by the master to have this sort of access? Do I simply create a new instance of the clients main forms? Should I do this in seperate threads to avoid locking up the master program while the clients are working? Or do I have to somehow use Application.Run(), if so how do I do this? Are there any severe pitfalls I am missing?
Help would be appreciated,
Stephan
|
|
|
|
|
stephan.smolek wrote: The clients can all be started seperatly by the user, or the master application starts them automaticly to have the standard user interaction of the client programs and also automated interaction / control with the master program.
The only way to start the other applications is by using the Process class to launch them.
stephan.smolek wrote: also automated interaction / control with the master program
You cannot just expose public methods and expect to be able to call them acrossed AppDomain boundries. You're going to have to learn about .NET Remoting, or Windows Communication Foundation, and setup remoting servers and clients in your applications to handle the communication and you'll also have to carefully design your applications to expose their functionality through various object models, kind of like how Word and Excel do it.
|
|
|
|
|
hi all,
Can anyone knows how to capture the desktop of a remote machine and save it as an image. I have tried and able to capture my same system. But not able to capture the remote machine's desktop.
Thanks and regards
Anez.A
|
|
|
|
|
It cannot be done unless oyu have code running on the remote machine doing the capture and sending the data to your local "server" code.
You may want to Google for and look into "VNCSharp".
|
|
|
|
|
Thank you for ur information.
But, it can be done...
i have seen one application.
Anyway, i'l try to implement .....
|
|
|
|