Handle [Ctrl + Enter] keyevent in a multiline textbox in c#

  private bool keydowncalled = false;
        private void txtAnswer_KeyDown(object sender, KeyEventArgs e)
        {
            //if (e.KeyData == Keys.Control && e.KeyData== Keys.Enter)
            //{
            //    e.SuppressKeyPress = true;
            //    e.Handled = true;
               
            //}

            keydowncalled = false;

            if (e.KeyData == Keys.Enter ) //(Keys.Control | Keys.Enter))
            {
                keydowncalled = true;
                AddMoreQuestion();
            }
        }

        private void txtAnswer_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (keydowncalled == true)
            {
                e.Handled = true;
            }
        }

        private void cmbQuestions_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData==Keys.Enter)
            {
                Question question = cmbQuestions.SelectedItem as Question;

                if (question.QuestionId == 0)
                {
                    MessageBox.Show(“Please select a question.”); return;
                }
                else
                {
                    txtAnswer.Focus();
                }
            }
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s