|
Can anyone explain to me how I can detect a key pressed and deal with it in one piece of code whatever component has the current focus. I have trawed through the help files but most of what is thrown up pre-supposes a certain level of knowledge (i.e. that you know what you are doing!).
I have a little program which controls the speed and timing (on/off) of a motor and I need to be able to stop the motor when any key is pressed as quickly as possible for safetly reasons whatever control currently has the focus.
regards,
Ted
Ted Edwards
|
|
|
|
|
Hello,
I'm not sure if it works in every situation (actually I know it's not, because I had problems with a PDF viewer Control in this case), but you can try this in your main form.
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(...);
this.KeyPress + = ...
Hope that helps a little!
All the best,
Martin
|
|
|
|
|
Thanks Martin, I think you have pointed me in the right direction. It works if I point each component's KeyDown event handler at the new form KeyDown event handler. I will have to differentiate between keys or the components which are suppose to accept new values from the keyboard - won't!
Thanks for your help,
Ted Edwards
|
|
|
|
|
You need either to grab the parents form key down event or you can set up a hook to grab the event whether this form is focused or not.
|
|
|
|
|
Hello,
I wanted to say that it's a feature of the Forms class.
You don't have to hook on the Controls eventhandler.
Try it out on your main form and you will see.
All the best,
Martin
|
|
|
|
|
Yes, I think I see what you mean - I am trying it but the new form keyboard event handler is having trouble with the statment: if (e.KeyChar >= 48 && e.KeyChar <= 57) which gives an error Error: 'System.Windows.Forms.KeyEventArgs' does not contain a definition for 'KeyChar'
What you both suggested seems to be the correct approach for what I need. I will investigate further...
Ted Edwards
|
|
|
|
|
Hello,
Looks like you are trying the KeyDown EventHandler.
You have to use the KeyPress eventhandler.
In my example I just wanted to point out that you have to choose the eventhandler that fitts your needs.
All the best,
Martin
|
|
|
|
|
Thanks for all the help - everything is working now. A quirk was that I had event handler for form plugged in from both code and form event handler properties which compiled okay but handler was called twice when run.
regards,
Ted Edwards
|
|
|
|
|
I want to know the answers of these qustions
are these true or false.....in both cases provide justification...thanks
(a) testing of non web based software system is completly different from based software system.?
(b) design phase of object oriented system need more cost and effort than design phase of functional oriented system?
(c) message passing features of object oriented paradigm play an important role in effecting effecincy of object oriented system?
(d) maintanance of file based system is cheaper in terms of time and effort than data based system.?
|
|
|
|
|
Wow, I'm allways so nervious when I have to do a test.
Maybe somewbody else stays a little
|
|
|
|
|
rao raja wrote: are these true or false.....in both cases provide justification.
I'll do your homework for $50 a question. Google is cheaper.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
thanks.for sugesting google.actually i just want to disscuess those..if u dont knw ..does not matter.
|
|
|
|
|
rao raja wrote: ..if u dont knw ..does not matter.
He knows the answer - but he is right to say that the questions look like homework. If you want to discuss these subjects then you might like to phrase the questions in such a way that it looks like you are discussing the subject out of genuine interest rather than as an answer to a homework question.
|
|
|
|
|
For a good discussion it would be helpfull to know your points.
|
|
|
|
|
rao raja wrote: if u dont knw ..does not matter
ROTFL - of course I *know*. But, if you want discussion, you need to lead off. If you want homework answers, you're in the wrong place.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: I'll do your homework for $50 a question
Is that Australian dollars or US Dollars?
|
|
|
|
|
rao raja wrote: (a) testing of non web based software system is completly different from based software system.?
Yes. One you test over the web, the other you don't.
rao raja wrote: (b) design phase of object oriented system need more cost and effort than design phase of functional oriented system?
No. An object oriented system doesn't need much design you can just get stuck in and code away. A procedural based system needs lots of planning and design to decide on the properties and methods of all those procedures!
rao raja wrote: (c) message passing features of object oriented paradigm play an important role in effecting effecincy of object oriented system?
No. All object oriented systems are pretty useless at passing messages. This forum is an object oriented system and look at how craply most messages are passed here? (See OP for evidence)
rao raja wrote: (d) maintanance of file based system is cheaper in terms of time and effort than data based system.?
No. File based system have lots of files, database systems usually only have one database. One vs many, easy answer!
That'll be $50 please.
PS If google gives you a different answer to any of these its lying!
|
|
|
|
|
The reason I didn't answer is, if it's his homework, he's not going to learn anything by copying your answer, now is he ?
badgrs wrote: This forum is an object oriented system
Are you sure ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
rao raja wrote: testing of non web based software system is completly different from based software system.?
Defining testing? As a general concept, testing is making sure something works as specified.
rao raja wrote: design phase of object oriented system need more cost and effort than design phase of functional oriented system?
Again design is a bit of a generalization. A more detailed design is going to cost more time and resources than a top level design.
rao raja wrote: d) maintanance of file based system is cheaper in terms of time and effort than data based system.?
Depends on who is doing it and who built the file system. I've spent many a hour fixing flat file based systems, where as something like SQL Server has lots of tools alreafy built in.
|
|
|
|
|
rao raja wrote: (a) testing of non web based software system is completly different from based software system.?
Testing is a waste of time, because you'll never discover all the problems. It's much more efficient to ship an untested product and have your customers report the problems.
rao raja wrote: design phase of object oriented system need more cost and effort than design phase of functional oriented system?
Design is expensive and pretty much worthless. What you want to achieve is the longest development cycle possible due to continual rewrites so that you can continue drawing a lucrative salary and the venture capitalist funding your company can continue writing off business losses on his taxes.
rao raja wrote: message passing features of object oriented paradigm play an important role in effecting effecincy of object oriented system?
OOP message passing is archaic technology. Current trends are moving toward quantum principles in which the receiver gets the message before the sender sends it.
rao raja wrote: maintanance of file based system is cheaper in terms of time and effort than data based system.?
Definitely. A flat file based system is much cheaper to maintain since you don't have to worry about indexing, performance, optimization, clustering, distributed servers, etc. All you need is a big hard disk, and hard disk prices are plummetting. Just last week my client discovered he could buy a 400GB hard disk for the same price that a 320GB hard disk was selling for six months ago.
rao raja wrote: are these true or false
All true!
Marc
Thyme In The CountryPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
|
Superb, pity I read this after my post otherwise it would have ended up under here
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
There are no right and wrong answers to those questions if you give your reasoning - they seem pretty subjective to me.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Can any one tell me why do I get this message from my catch block..
Cannot write to the registry key
I'm trying to write to the registry using the following code
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
key.SetValue("X", "xxx", RegistryValueKind.String);
Please advise,
Many thanks
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hello,
The OpenSubKey method has the possibility to set the key writeable.
Just use the second parameter (BOOLEAN).
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
All the best,
Martin
|
|
|
|