NumPad UserControl?

torread

Member
Joined
Nov 6, 2009
Messages
8
Programming Experience
Beginner
Hi to all! I'm new in vb.net and I'm trying to create a usercontrol simulating a NumPad (numbers from 1 to 9, sum not included only numbers). My idea is to create this control and then added to a WinForm that will have some Login form and the user uses this numpad control to access the Application. User will have a touch screen monitor, no keyboard is installed, that why I need to create this usercontrol. The problem is, don't know how to created. I already have the Numpad With the button Created and a test Textbox on the UserControl (Which I will delete after knowing that the buttons works) but at this moment they are not working.
Example of the Code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms

Public Class NumPad

Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
SendKeys.Send("{7}")
End Sub

Can anyone help me???
 
If there are many textboxes using this control - use a Public Property on the UC that will hold the reference to the textbox, so each button will add to the property (destination textbox) til it losses focus/enter button whatever. The textbox.click event would be a good place to reference the UC's destination textbox property ( i.e where the input goes). I made one once, let me see if I can find it. Mean while play with this and see what you come up with. Oh and I would not use SendKeys, just use the button's text property or string value.
 
I set the Focus to the TextBox that I have on the User Control and it is working, but this is only for test purpose, the user control wo't have the Textbox, instead the for will have the Textboxes, so how can I Achieve that this Control works on my form. You told me something about Public and the CLick method, could you give some code Example. Thanks!!!!

Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
SendKeys.Send("{7}")
TextBox1.Focus()
End Sub
 
Use a Public property As Textbox on the UC, then when a textbox gains focus/enter then change this value to that textbox, then in the click event of the numberkey buttons this property can be used to update the text in the textbox that has focus. You also only need one click event for the UC buttons, cause we will use the sender object to get it's text property. I'll see if I have more time later to get you code sample.
 
The UserControl class in in this text file, I tested it with the Enter event and in the event I used this:
VB.NET:
Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter
    UC1.DestinationBox = CType(sender, TextBox)
    UC1.Value = 10 'max characters
End Sub
Just an idea to get ya started...:cool:
 

Attachments

  • NumberKeyPad.txt
    6.6 KB · Views: 38
Where do I define de UC1 because if a declare it on the UserComponet it give me an error also on the form after inserting the UserControl. I change it to the name of my user control (of course).
 
I dropped the control on the form, I named it UC1(designer name). The control name can be whatever you want, but when you drop the control the designer will name it that plus 1.
(example) I named the component UserControl in the designer it would be UserControl1 unless you change it. Like any other control go to the properties window for that control and set the name.
 
This is the error:
'DestinationBox' is not a member of 'NumPad.NumberPad'
'Value' is not a member of 'NumPad.NumberPad'
 
Did you look at the text file I sent in post number 6. Here you find those properties. You must have them in your control code or you can't use them. There is more to the story than just adding those properties. Take a look at the code you will see the m_Destbox variable is updated with the number buttons.
 
I didnt see that txt file. Now it is working great. But I have one question. In my NumPad Control I have a Button that I want to function equals to the Keyboard Delete Button, I have tried SendKeys.Send({"DELETE"}) but instead of erase a character it deletes the complete text of the textbox. How can I achieve that it erase a singular character?
 
Have you also added the arrow keys? Then you could move the caret to a position and SelectionStart is the index of the string then just remove the next character with the Remove Function.
 
Ok, but the Delete key removes the character in front of the caret - which made me think you where moving the caret. Do you mean Backspace instead?
 
Yeah it could be like BackSpace but when i made the SendKeys.Send({DELETE}) or SendKeys.Send({BACKSPACE}) what it makes is that it deletes all in the textbox instead of one character at the time.
 
Back
Top