Question

Create a C# Form with a textbox and a button. The box is for a user...

Create a C# Form with a textbox and a button. The box is for a user to enter a number of seconds. And when the user clicks the button, the program displays the equivalent number of hours, minutes and seconds using a MessageBox. Show method. If the seconds entered is less than 60, your program should only display the seconds; if the seconds is a least 60 and less than 3600, your program should display minutes and seconds; if the second is at least 3600, your program should display hours, minutes and seconds. Use the following data to test your program: 47 seconds: 47 seconds (don’t show 0 hour and 0 minute) 645 seconds: 10 minutes, 45 seconds (don’t show 0 hour) 7565 seconds: 2 hours, 6 minutes, 5 seconds Requirements: 1. Input validation: The number of seconds cannot exceed 86400. You must use textbox’s Validating event to do the validation

For Visual Studios 2017 in C#, Windows Form app

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "TimeApplication".This application contains a form with name "Form1.cs".Below are the files associated with form1.

1.Form1.cs[Design]

2.Form1.cs

//namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//application namespace
namespace TimeApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//time button click
private void btnTime_Click(object sender, EventArgs e)
{
//desclring variable to store seconds
int seconds=int.Parse(txtSeconds.Text);
//checking seconds
if(seconds<60)
{
//display only seconds
MessageBox.Show(seconds + " seconds","Time");
}
else if(seconds>=60 && seconds<3600)
{
//if seconds are 60 to 3600
int min = seconds / 60;
int sec = seconds % 60;
//display miutes and seconds in the messagebox
MessageBox.Show(min + " minutes ," + sec + " seconds", "Time");
}
else if(seconds>=3600)
{
//if seconds are greater than or equal to 3600
int hours = seconds / 3600;//finding hours
seconds = seconds % 3600;
int min = seconds / 60;//finding minutes
seconds = seconds % 60;
//display hours,minutes and seconds
MessageBox.Show(hours + " hours," + min + " minutes," + seconds + " seconds", "Time");
}
}
//validating event of the textbox
private void txtSeconds_Validating(object sender, CancelEventArgs e)
{
//checking seconds should not exceed 86400
if (int.Parse(txtSeconds.Text) > 86400)
{
//if seconds are greater than 86400
MessageBox.Show("Enter seconds less than 86400", "Time");
}
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :

Screen 2:Screen showing seconds

Screen 3:Screen showing seconds and minutes

Screen 4:Screen showing seconds ,minutes and hours

Screen 5:Screen when seconds exceeds 86400

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Create a C# Form with a textbox and a button. The box is for a user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • How do I program this problem using c++. Create a process to prompt the user to...

    How do I program this problem using c++. Create a process to prompt the user to enter the number of seconds and determine the whole number of days, hours, minutes, and seconds corresponding to the entered number of seconds. For example if the number of seconds entered was 183945, then 2 days, 3 hours, 5 minutes and 45 seconds should be displayed. There are 86400 seconds in a day, 3600 seconds in an hour, and 60 seconds in a minute....

  • Purpose of the assignment To apply simple JavaScript concepts to create a Fahrenheit to Celsius (and...

    Purpose of the assignment To apply simple JavaScript concepts to create a Fahrenheit to Celsius (and Celsius to Fahrenheit) conversion program. I need both please! What’s required of you. Having looked at some basic examples of JavaScript on http://www.w3schools.com and at the “simple math with forms/inputs and validation” example in detail , I would like you to now apply those concepts to create a simple page that lets users type in some temperature value in the Fahrenheit/Celsius scale and when...

  • Create a GUI program (a Windows Forms Application) called GooseEggCalculator that lets a user enter the...

    Create a GUI program (a Windows Forms Application) called GooseEggCalculator that lets a user enter the number of eggs produced by each of four geese. Your program should provide textboxes with labels for the user to enter the values. When the user clicks a Calculate button, your app should sum the textboxes, then display the total number of eggs, as well as the number of eggs in dozens and remaining eggs, as shown on the example. Feel free to make...

  • Write a complete C program for an automatic teller machine that dispenses money. The user should...

    Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense. When writing your function begin to pass your variables using pointers (or rather "pointing" to your data". Use the TimeSpace program...

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

  • Create an application with the following requirements: 1 form graphic on the form itself, along with...

    Create an application with the following requirements: 1 form graphic on the form itself, along with various others depending on the graphics used You pick the form color or additional graphics The program should generate a random number(1 and 100). A label that asks the player to think of a number between 1 and 100. The player should be able to enter their guess into a textbox. The program should validate the users entry to make sure its: A number,...

  • how to add methods into thjs code using C# on visual studio? -validatetextbox should return a true false depending if input is valid -resetinput should clear all input and restart radiobuttons...

    how to add methods into thjs code using C# on visual studio? -validatetextbox should return a true false depending if input is valid -resetinput should clear all input and restart radiobuttons to the defult positions -displaymessge must display messge box to the user displaying such as “5+8=12” calculator.cs x Prearam S Miscellaneous Files ator.Designer.c s Calculato 1 曰using Systemi 2 using System.Collections.Generic; using System.ComponentModel; 4 using System.Data; s using System.Drawing; 6 using System.Linq 7using System.Text; 8 using System.Threading.Tasks; 9 using...

  • Need some assistance of reorganizing this whole program. I have the right code for everything I...

    Need some assistance of reorganizing this whole program. I have the right code for everything I just need help on putting all the codes in the right spot so it can come out to the correct output. output is supposed to look like this: 1 \\ user inputs choice to convert 12 to 24 8 \\ user inputs 8 for hours 30 \\ user inputs 30 for minutes 20 \\ user inputs 20 for seconds AM \\ user inputs AM...

  • This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display...

    This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT