You must Sign In to post a response.
  • Category: Windows

    Button Click on Key Press

    I have completed a calculator project design and functions and want to know how to call a particular button's click event on a particular key press as we do in the normal calculator available with windows OS.

    Previously I had asked this question and got complete code for developing calculator in return. I don't want complete code. Just provide me a piece of code and some hints on how to make a button's click happen on a particular key press. I will take care of rest of the things.

    Any help in this regard will be appreciated.
  • #620542
    Hi Sibtain,

    try this ,

    1. Please set Form1 KeyPreview=True .

    2. Sample code

    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 WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }



    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (e.KeyChar == 55)
    {
    btn7.PerformClick();
    }
    }

    private void btn7_Click(object sender, EventArgs e)
    {
    MessageBox.Show("You clicked No 7");
    }


    }
    }


    3. Please check attached document.

    thanks.

    flash_keycodes.pdf

    Delete Attachment

  • #620553
    Hi,

    In VB.net we can call a button click event in another place like this

    Button_Click(Nothing,Nothing)

    Thanks
    Ganeshgoud

  • #620572
    Mr.karthikeyan's solution is proper and exact as per my requirement. Now I am finalizing the calculator which speaks.

    Yes ! I have made a calculator with integrated speaking technology. It speaks what ever number you give input, the operation you select and reads the result loud ! Soon I'll post it in the project section.

    Your help was really critical for the success of this application .. hence thanks a ton Mr.karthikeyan !!!

    Regards,
    Sibtain Masih
    "Man is still the most extraordinary computer of all."

  • #620756
    Hi Sibtain,
    It's great that you have created such a good calculator...but as per your description for the implementation of the keypress event..for the buttons you places in the form control...we can have couple of more ideas to implement the same.
    Instead of taking the buttons separately, we cna have an image of calculator and we can place the whole image on the window form and then we can have click event which will find out the number or operator based on the x-y coordinate of the image.. Like this way you can perform all the operations..
    Like this i implemented one of my project where the requirement was something like it should have whole keyboard and then it should work similar to the keyboard we have for out systems. for that i implemented the logic i explained before.
    By the way its great achievement to develop such a speaking calculator..
    we would like to see it soon..

    pawan

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #620758
    Yeah Mr. Pawan! Great idea !

    Actually I have made it for one of my friend who is visually impaired. The retina of his eye is not able to capture the images properly as it is not constant and not under the control of his brain. If he want to see something he need to put a lot of pressure on his eye then only he can see something for very few seconds. Doctor said the ratio of this disease is 1 : 1lac and the research is going on to find the cure. He uses computer and plays games too up to certain extent !

    So i was thinking of giving him some gift and I designed a calculator which reads everything. I have made the fonts size big too and the calci takes entire screen space. So it will be easier for him to read and as the calci will speak, I am sure he will like it. I am going to present it to him on his birthday this month.

    Simultaneously, I made a normal calci which we see in windows. This I'll post here soon.

    I am confused. Should I post it in articles or in projects. I have asked Mr. Raghav for guidelines. As soon as I will get his reply, I'll take next step accordingly.

    And soon I'll roll out calci's next version with a nice calci image and it will be an implementation of your idea.

    Thanks for giving me the spark ! I'll surely fan it into a flame !

    Regards,
    Sibtain Masih
    "Man is still the most extraordinary computer of all."


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.