Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7712907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:44:31+00:00 2026-06-01T01:44:31+00:00

I have a c# program using WPF. I have it that when you press

  • 0

I have a c# program using WPF. I have it that when you press a key, it will click on a button and then disable the button. My issue is that, once I decide to click on a button, the keyDown event no longer gets executed. Am I missing something?

namespace FindTheCat
{
    public partial class MainWindow : Window
    {
        private Treasure treas;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void checkForKitty(object sender, RoutedEventArgs e)
        {
            ToggleButton button = (ToggleButton)e.OriginalSource;

            if(button != null)
            {
                button.IsEnabled = false;

                int loc = getLocation((String)button.Content);

                if (loc > 0)
                {
                    isFound(loc);
                }
            }
        }

        private void checkKey(object sender, KeyEventArgs e)
        {
            ToggleButton item = (ToggleButton)GridRoot.FindName(e.Key.ToString());
            if (item != null)
            {
                item.IsEnabled = false;
                int loc = getLocation(e.Key.ToString());

                if (loc > 0)
                {
                    isFound(loc);
                }
            }

            MessageBox.Show("Key Pressed");
        }

        private void isFound(int loc)
        {
            Boolean found = treas.isFound(loc);

            if (found)
            {
                MessageBox.Show("YAY! You found the cat!");
                Reset();
            }
            else
            {
                MessageBox.Show("Boo! You did not find the cat!");
            }
        }

        private int getLocation(String letter)
        {
            switch (letter)
            {
                case "A":
                    return 1;
                case "B":
                    return 2;
                case "C":
                    return 3;
                case "D":
                    return 4;
                case "E":
                    return 5;
                case "F":
                    return 6;
                case "G":
                    return 7;
                case "H":
                    return 8;
                case "I":
                    return 9;
                case "J":
                    return 10;
                case "K":
                    return 11;
                case "L":
                    return 12;
                case "M":
                    return 13;
                case "N":
                    return 14;
                case "O":
                    return 15;
                case "P":
                    return 16;
                case "Q":
                    return 17;
                case "R":
                    return 18;
                case "S":
                    return 19;
                case "T":
                    return 20;
                case "U":
                    return 21;
                case "V":
                    return 22;
                case "W":
                    return 23;
                case "X":
                    return 24;
                case "Y":
                    return 25;
                default:
                    return 0;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            treas = new Treasure();
        }

        private void Reset()
        {
            treas.Reset();

            ResetButton("A");
            ResetButton("B");
            ResetButton("C");
            ResetButton("D");
            ResetButton("E");
            ResetButton("F");
            ResetButton("G");
            ResetButton("H");
            ResetButton("I");
            ResetButton("J");
            ResetButton("K");
            ResetButton("L");
            ResetButton("M");
            ResetButton("N");
            ResetButton("O");
            ResetButton("P");
            ResetButton("Q");
            ResetButton("R");
            ResetButton("S");
            ResetButton("T");
            ResetButton("U");
            ResetButton("V");
            ResetButton("W");
            ResetButton("X");
            ResetButton("Y");
        }

        private void ResetButton(String name)
        {
            ToggleButton item = (ToggleButton)GridRoot.FindName(name);

            if (item != null)
            {
                item.IsEnabled = true;
                item.IsChecked = false;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:44:32+00:00Added an answer on June 1, 2026 at 1:44 am

    A disabled control can not have the keyboard focus. So it won’t get any key events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that draws some vector graphics using System.Drawing and the Graphics
The Situation I have a WPF program that I want to print several documents
I have a wpf application that has a button for for each folder under
I'm working to build a .NET program with WPF that will need to be
I have a program in C using Solaris with VERY ancient compatibility it seems.
I have the following MonoTouch program: using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit; using System;
I have been asked to write a program using python for an assignment. I
i have made a small opengl program using the d programming language. what i
I have this problem when trying to run hello world program using android SDK.
I have a program which reads an XML file using the DOM functions: $doc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.