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

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 3393
    • View Profile
    • AdvancedHMI
Popup keypad for General TextBox Use
« on: March 20, 2017, 07: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, 09:31:23 AM »
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: 3393
    • View Profile
    • AdvancedHMI
Re: Popup keypad for General TextBox Use
« Reply #2 on: April 21, 2017, 09:46:38 AM »
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, 09:54:41 AM »
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

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Popup keypad for General TextBox Use
« Reply #4 on: April 23, 2017, 04: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: 3393
    • View Profile
    • AdvancedHMI
Re: Popup keypad for General TextBox Use
« Reply #5 on: April 24, 2017, 05: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

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Popup keypad for General TextBox Use
« Reply #6 on: April 29, 2017, 07: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