Author Topic: Popup keypad for General TextBox Use  (Read 6069 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Popup keypad for General TextBox Use
« on: March 20, 2017, 10:07:00 AM »
This is a very simple method to allow a user to enter a value in a TextBox without a physical keyboard. I used the double click event in order to allow the option of single click for physical keyboard and double click for virtual keyboard.

- In Solution Explorer, double click MainForm.vb to open in design view
- In the Toolbox, under All Windows Forms group, add a TextBox to the form
- With the TextBox selected, go to the Properties Window and at the top click the lightening bolt to see the event list
- Find the DoubleClick and double click in the are to the right of it. This will take you back to the code
- Insert the code shown here:
Code: [Select]
    Private Sub TextBox1_DoubleClick(sender As Object, e As EventArgs) Handles TextBox1.DoubleClick
        Dim kpd As New MfgControl.AdvancedHMI.Controls.AlphaKeyboard
        If kpd.ShowDialog = DialogResult.OK Then
            TextBox1.Text = kpd.Value
        End If
    End Sub

- Run the application and double click on the Textbox

mpshannon23

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Popup keypad for General TextBox Use
« Reply #1 on: April 21, 2017, 12:31:23 PM »
Do you have example code of this in C#.  When I am trying to code this in C# I get an error in the If statement for kpd.ShowDialog = DialogResult.OK

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Popup keypad for General TextBox Use
« Reply #2 on: April 21, 2017, 12:46:38 PM »
Do you have example code of this in C#.  When I am trying to code this in C# I get an error in the If statement for kpd.ShowDialog = DialogResult.OK
Code: [Select]
private void TextBox1_DoubleClick(object sender, EventArgs e)
{
MfgControl.AdvancedHMI.Controls.AlphaKeyboard kpd = new MfgControl.AdvancedHMI.Controls.AlphaKeyboard();
if (kpd.ShowDialog == DialogResult.OK) {
TextBox1.Text = kpd.Value;
}
}

mpshannon23

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Popup keypad for General TextBox Use
« Reply #3 on: April 21, 2017, 12:54:41 PM »
One change had to be made.  kpd.ShowDialog should be kpd.ShowDialog().  See code below.
Code: [Select]
private void TextBox1_DoubleClick(object sender, EventArgs e)
{
MfgControl.AdvancedHMI.Controls.AlphaKeyboard kpd = new MfgControl.AdvancedHMI.Controls.AlphaKeyboard();
if (kpd.ShowDialog() == DialogResult.OK) {
TextBox1.Text = kpd.Value;
}
}

Phrog30

  • Guest
Re: Popup keypad for General TextBox Use
« Reply #4 on: April 23, 2017, 07:58:11 PM »
What have you done about restricting characters?  For example, if I only want them to enter numbers?  I currently have this code written, but for the textbox, is there a good way of limiting the keyboard before they send to the object?

James

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Popup keypad for General TextBox Use
« Reply #5 on: April 24, 2017, 08:49:50 AM »
What have you done about restricting characters?  For example, if I only want them to enter numbers?
You could use the MfgControl.AdvancedHMI.Controls.Keypad if it is only numeric input

Phrog30

  • Guest
Re: Popup keypad for General TextBox Use
« Reply #6 on: April 29, 2017, 10:03:44 AM »
What have you done about restricting characters?  For example, if I only want them to enter numbers?
You could use the MfgControl.AdvancedHMI.Controls.Keypad if it is only numeric input

Thanks for the input Archie.  The more I thought about it, the code needs to be part of the "object", since if the application is being run on a desktop they won't be using the popup keyboard or calculator.

James