Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello every one, I'm a newbie in programming yet I know some logic in running a windows application. Can anybody help me in coding my Mobile keypad alike in Windows Form Application?

Here is sample of the code snippet:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace mobileKeypad
{
    public partial class Form1 : Form
    {
       

        int abc;
        int def;

        public Form1()
        {
            InitializeComponent();
        }

        private void btn2abc_Click(object sender, EventArgs e)
        {

            abc++;

            if (abc == 5)
                abc = 1;


            switch (abc)
            {
                case 1: txtDisplayTxt.Text = "a";
                    break;
                case 2: txtDisplayTxt.Text = "b";
                    break;
                case 3: txtDisplayTxt.Text = "c";
                    break;
                case 4: txtDisplayTxt.Text = "2";
                    break;
            }
        }

        private void btn3def_Click(object sender, EventArgs e)
        {

            def++;

            if (def == 5)
                def = 1;


            switch (def)
            {
                case 1: txtDisplayTxt.Text = "d";
                    break;
                case 2: txtDisplayTxt.Text = "e";
                    break;
                case 3: txtDisplayTxt.Text = "f";
                    break;
                case 4: txtDisplayTxt.Text = "3";
                    break;
            }
        }

    }
}

The problem is, whenever I press button 2, it happens to show only the letters but when I press other buttons, it the text don't append with the current value of text instead it overwrites the current value of the textbox. Can anyone help me to repair it? What I want to happen is make the buttons append with the current values of textbox, can it work without the help of timer? Or timer should be there?
Posted
Updated 10-Oct-12 21:37pm
v7
Comments
[no name] 10-Oct-12 14:39pm    
Besides not trying anything yourself, your whole idea is flawed. Say someone clicked the button once and an "a" appeared in the textbox. How are you going to differentiate one click from two clicks and three clicks? Is click.... click one click twice so "aa" should appear? Or is it counted as two clicks so "b" should appear?
RaR16 10-Oct-12 14:48pm    
You try to read again my question. What I want to say is whenever you click a button right? So does OTHER BUTTON means the button I mentioned first? I didn't told to make 26 clicks to get a "z". I'll return your question, does a mobile keypad has only 1 button?
[no name] 10-Oct-12 15:33pm    
Oh no don't bother answering the question put to you. Guess you really don't need any help. Good luck.

 
Share this answer
 
Comments
fjdiewornncalwe 10-Oct-12 16:22pm    
+5. You are correct, I do know that article. :)
Sergey Alexandrovich Kryukov 10-Oct-12 16:26pm    
Thank you, Marcus.
--SA
RaR16 10-Oct-12 22:14pm    
Well sorry for that. My fault :)
Sergey Alexandrovich Kryukov 10-Oct-12 22:43pm    
No problem. Let's go ahead.
--SA
RaR16 10-Oct-12 22:15pm    
I'll just rephrase my question.
You may use a timer. Suppose we're dealing with button '2':
you need a set of states, e.g.
{ FIRST_CHOICE, SECOND_CHOICE, .., IDLE}
and corresponding symbols, e.g.
symb[FIRST_CHOICE]='a' symb[SECOND_CHOICE]='b', ..


  1. The user clicks the button for the first time (that is button was IDLE), then the timer starts, the button state becomes FIRST_CHOICE (and you show 'a').
  2. If the timer expires before further clicks then FIRST_CHOICE is the definitive choice ('a' remains) and buttons state returns IDLE.
  3. If the user clicks before timer expiration then you put button state to SECOND_CHOICE (replacing 'a' with 'b'), kill the timer and restart it.
  4. Perform step 3 as many times as needed passing from SECOND_CHOICE to THIRD_CHOICE and so on (handling wrap around, e.g. NINETH_CHOICE -> FIRST_CHOICE) until the user slows down OR clicks another key (that is button becomes IDLE).
 
Share this answer
 
v3
Comments
RaR16 10-Oct-12 22:15pm    
Thanks for the idea :)
CPallini 11-Oct-12 3:23am    
You are welcome.
RaR16 11-Oct-12 3:24am    
By the way can we make it without the timer?
CPallini 11-Oct-12 3:26am    
Short answer: no.
Somewhat longer answer: using the timer is probably the simplest way to accomplish the task (you have to handle time delays).
RaR16 11-Oct-12 3:28am    
Oh I see, in the case on my code snippet above, can you tell me where to put the timers and delays code? :/
Here are some simple steps
1) Try to do it yourself.
2) When you have issues with specific coding concerns, ask a question related to that.

Why?[^] Compliments of JSOP
 
Share this answer
 
Comments
joshrduncan2012 10-Oct-12 13:44pm    
I agree with Marcus! This is only a forum to help with specific questions about certain pieces of code that are tripping you up, not creating a program from scratch.
RaR16 10-Oct-12 14:14pm    
Well sorry for that. I don't even have idea for the coding. That is why I am asking you, experts in C#, so that I can understand and apply it well. I'm almost done with the program, that is the only problem I have that is why I'm trying to ask for help.
fjdiewornncalwe 10-Oct-12 14:57pm    
If you're almost done the program, share a code snippet of what is giving you difficulty and we'll gladly answer that. Cheers.
Sergey Alexandrovich Kryukov 10-Oct-12 16:17pm    
Fair enough, my 5. This time, I also decided to use an available article which you probably know -- please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900