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 9137337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:29+00:00 2026-06-17T09:05:29+00:00

I have a question about a small practice program I’m working on. I have

  • 0

I have a question about a small practice program I’m working on. I have almost no experience with C#, and a little bit of experience with Visual Basic. The problem I’m having has to do with only allowing numbers in the text box. I succeeded in doing so in another program, but for some reason it isn’t working with relatively the same code.
Here is the 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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            Double TextBoxValue;
            TextBoxValue = Convert.ToDouble(txtMinutes.Text);
            TextBoxValue = Double.Parse(txtMinutes.Text);

            {
                Double Answer;
                if (TextBoxValue > 59.99)
                {
                    Answer = TextBoxValue / 60;
                }
                else
                {
                    Answer = 0;
                }
                {
                    lblAnswer.Text = Answer.ToString();
                }
            }

        }

        private void txtHours_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsNumber (e.KeyChar) && Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
} 

If there are other errors in my code that anyone here can correct me on, that is also appreciated. Thanks in advance.

  • 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-17T09:05:29+00:00Added an answer on June 17, 2026 at 9:05 am

    Your logic is incorrect. It states “if the pressed key is a number and a control character.. then i’ve handled it”. What you want is “if the pressed key is NOT a number, I’ve handled it”.

    if (!char.IsNumber(e.KeyChar)) {
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about a small problem I am having in Magento. When
I have a small question about a problem I encountered writing my first python
I have a question about scanner please;I working at a small company; we have
I have a small question about the Core Bluetooth framework. I know Core Bluetooth
I'm using BerkeleyDB to develop a small app. And I have a question about
I have a small question about structures with the LayoutKind.Explicit attribute set. I declared
I have a small question about dojo: I have a div: <div id=image class=classImage>
I have a small question about threads. On Unix systems, we have nice ,
I have a small question about a certain css navigation technique where an end
Hello everyone I have a small question about array in array and how to

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.