If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Help: Numeric Keypad with multi-textboxes

That code is so much more complex than is necessary. Firstly, you've written basically the same code over and over and that is never a good thing. One of the most important principles in programming is DRY: don't repeat yourself. You could simply assign the appropriate digit to the Tag property of each Button and then use a single method to handle the Click event for all of them. In the event handler, you access the Button that was clicked via the 'sender' parameter and get the digit to use from its Tag.

Secondly, you don't need If statements to determine which TextBox has focus. You simply get the ActiveControl of the form and, if it's a TextBox, append the appropriate text, which you get from the Button's Tag, e.g.

The other issue you have, though, is that clicking a Button will steal focus, so the ActiveControl will never be one of the TextBoxes. You need a way to click the Button without it taking focus. To learn how to do that, follow the CodeBank link in my signature and check out my On-screen Keyboard thread. The custom controls provided their are already designed for an on-screen keyboard, so there's a button control that will not take focus when clicked and also has a property specifically for the character that that "key" represents.

Re: Help: Numeric Keypad with multi-textboxes

Thank you for the help.
Sorry for that. i am just a starter.
I cannot find your thread on creating the On-Screen Keyboard, I only found the On-screen Keyboard: Active Window Loses Focus for External Apps

Re: Help: Numeric Keypad with multi-textboxes

Hey, no one knows these principals to begin with. Unfortunately, simple principles like DRY don't get taught as early as they should either.

Anyway, with regards to that CodeBank link, the search feature for this site still doesn't seem to work properly, or certainly not the way it did, so those links in my signature don't always show all the threads they should. You can still find the thread easily enough though. Just go to the VB.NET CodeBank forum, sort by Thread Starter and then page until you find my threads. It should about page 13 or 14.

Re: Help: Numeric Keypad with multi-textboxes

Hi abo0badr,

I have an example for you that may prove useful (See my signature for the link.). Not to long ago I found myself requiring my own on-screen numpad for a project I was working on to. So I went ahead and built one. Unfortunately though it was not as simple as I had originally thought, on-screen numpads, when for the users end require some attention to detail. Some going through with a fine tooth pick and comb am I right?

Hope it helps you out a bit, do take note in my example I had to strip away a lot because of how 'implemented' it was in my other project, design and functionality-wise.

Feel free to message me for any question you may have. If they're useful to the thread, post it here so others can see.

Re: Help: Numeric Keypad with multi-textboxes

hello sir, I tried your example and it was pretty awesome, but I am in a little bit trouble that I cannot solve, when I run your program as it's project, it is perfectly running, but I integrated the example in my system (actually it's just a start, not yet fully functioning, I just created it) and the numpad comes up, but it does not code any numbers..

maybe because I used it in a panel? Here attached my Program, I hope you can find what is wrong,