__________     __ __     __  _______    ________
  / ____/ __ \   / // /    / / / /  _/ |  / / ____/
 / / __/ / / /  / // /_   / /_/ // / | | / / __/
/ /_/ / /_/ /  /__  __/  / __  // /  | |/ / /___
\____/\____/     /_/    /_/ /_/___/  |___/_____/

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

C# Graphics User Interface to create a simple Windows Forms countdown timer

BY: @branx | CREATED: March 27, 2018, 7:30 p.m. | VOTES: 5 | PAYOUT: $0.00 | [ VOTE ]

What Will I Learn?

Requirements

Get Microsoft visual studio 2012 here

Difficulty

Tutorial Contents

Hello utopian, welcome to this tutorial. This happens to be my first tutorial and we will be looking at the concept of C# GUI, concept behind Timer control and creating a simple Windows Forms countdown timer.

C# Graphical User Interface

Graphical User Interface is an interactive display which presents graphical elements/widgets for the user to interact with. It's made of graphical element that provides easy use, more visual interface for users to operate without having to know lots of commands such as a text box, a button, label, check box, Timer etc.

What is Timer Control?

The Timer Control plays an important role in the development of programs both Client side and Server side development as well as in Windows Services. With the Timer Control we can raise events at a specific interval of time without the interaction of another thread.

How Timer Control Works?

A Timer control does not have a visual representation and works as a component in the background. We can control programs with Timer Control in millisecond, seconds, minute and even in hours. The Timer Control allows us to set Interval property in milliseconds. That is, one second is equal to 1000 milliseconds.

Example

A countdown timer is program that takes user input into a masked textbox, uses the Systems.Windows.Forms.Timer class to count down while displaying the remaining time, and then beeps at you with a message box when the time is up.

Steps to Create your GUI

[IMAGE: https://cdn.utopian.io/posts/2379c8f03a5d5877439c72810e31edeb43c6windowform.png]

[IMAGE: https://cdn.utopian.io/posts/f3bdc9c7f1d19bdf821d41ede4e4817c1096form.png]

Design your form as below

C# provide user with a toolbox that support Drag and drop of control on the Form

[IMAGE: https://cdn.utopian.io/posts/a397aee69a10099ef9e93ce641e392ec4134Desinview.png]

That is, you will have three label, Three Button, One Textbox, One Panel and Timer control.

Coding view

What I did first, I created a Message that displays the significance of the program.

then “this.Text = "Timer Application";” is to Rename the Title of the Form from the .Text Property.

While the “txtTimer.Text = "00:00";” is to set the Textbox default .text property to be "00:00" at runtime.

“paneltimer.Visible = false;” is to set the panel visibility to be false at runtime.


Private void Form1_Load(object sender, EventArgs e)
       {
                 MessageBox.Show(" A countdown timer is program that takes user input into a masked textbox, \n"
        + "uses the Systems.Windows.Forms.Timer class to count down while displaying the remaining time, "
        + " and then beeps at you with a message box when the time is up.","WELCOME UTOPAIN");
           this.Text = "Timer Application";
           txtTimer.Text = "00:00";
paneltimer.Visible = false;
       }
   }
On Click event of btnStart
private void btnStart_Click(object sender, EventArgs e)
        {
             if (txtTimer.Text == "00:00")
            {
                MessageBox.Show("Please enter the time to start!", "Enter the Time", MessageBoxButtons.OK);
            }
            else
            {
                // Convert text to seconds as int for timer
                string[] totalSeconds = txtTimer.Text.Split(':');
                int minutes = Convert.ToInt32(totalSeconds[0]);
                int seconds = Convert.ToInt32(totalSeconds[1]);
                timeLeft = (minutes*60) + seconds;

                // Lock Start and Clear buttons and text box
                btnStart.Enabled = false;
                btnReset.Enabled = false;
                txtTimer.ReadOnly = true;

                // start timer
                      timer1.Start();
            }
        }
On Click event of btnReset
private void btnReset_Click(object sender, EventArgs e)
        {
            txtTimer.Text = "00:00";
        }
On Tick event of timer1
private void timer1_Tick(object sender, EventArgs e)
        {
             if (timeLeft > 0)
            {
                timeLeft = timeLeft - 1;
                // Display time remaining as mm:ss
                var timespan = TimeSpan.FromSeconds(timeLeft);
                txtTimer.Text = timespan.ToString(@"mm\:ss");
                // Alternate method
                //int secondsLeft = timeLeft % 60;
                //int minutesLeft = timeLeft / 60;
            }
            else
            {
                timer1.Stop();
                SystemSounds.Exclamation.Play();
                MessageBox.Show("Time's up!", "Time has elapsed", MessageBoxButtons.OK);
            }
        }
On Click event of BtnStoP
private void BtnStoP_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            timeLeft = 0;
            btnStart.Enabled = true;
            btnReset.Enabled = true;
            txtTimer.ReadOnly = false;

        }
On Click event of lblproceed
private void lblproceed_Click(object sender, EventArgs e)
        {
            paneltimer.Visible = true;
               lblproceed.Visible = false; 
        }

OUTPUT

https://4.bp.blogspot.com/-t-jzcZDPFyo/WrqIEOwpliI/AAAAAAAAAH0/kYnnUVOQ8DIFXHc6XcfCWjqJbO14i_YnQCLcBGAs/s1600/output.gif

Download full source code on my GitHub if you need to try it out.

Curriculum

This is the first contribution in this curriculum. It will be succeed with more contributions.

Posted on Utopian.io - Rewarding Open Source Contributors

TAGS: [ #utopian-io ] [ #open-source ] [ #tutorial ] [ #programming ] [ #nigeria ]

Replies

@wafrica | March 27, 2018, 7:53 p.m. | Votes: 0 | [ VOTE ]

Dear friend! Next time also use #wafrica and follow @wafrica to get an upvote on your quality posts!

@branx | March 27, 2018, 8:05 p.m. | Votes: 0 | [ VOTE ]

Noted!

@roj | March 27, 2018, 8:34 p.m. | Votes: 0 | [ VOTE ]

Your contribution cannot be approved because it does not follow the Utopian Rules.

Related Rules:
- Only contributions made to open source projects with a GitHub repository can be approved.
- Submissions that include a GitHub repository with additional materials (like code samples), should be linked to the repository of the original project discussed in the tutorial and not the supplementary repository created for the contribution. Links to the supplementary repository for the post should be included in the submission post.
- Submissions to this category must include technical instructions that use text and graphics to clearly explain and teach significant aspects of an Open Source project.
- Content shared previously will be rejected if a moderator discovers plagiarism, and the user submitting it will be banned from Utopian.

Clarifications and Suggestions:
- Since C# doesn't have a proper repository, contributions on C# cannot be approved. And also it's not allowed to use tutorial files' repository as the linked repository since it's reserved for the project repository.
- Also, the tutorial mainly covers a simple and too specific example instead of teaching a significant aspect of the project.
- The content is plagiarized, and this is a reason for a direct rejection and may cause a ban from Utopian.

Source 1: http://csharp.net-informations.com/gui/timer-cs.htm

Source 2: http://www.geoffstratton.com/cnet-countdown-timer

You can contact us on Discord.
[utopian-moderator]

@steemitboard | Jan. 23, 2019, 10:15 p.m. | Votes: 0 | [ VOTE ]

Congratulations @branx! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@branx/birthday1.pngHappy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

> Support SteemitBoard's project! Vote for its witness and get one more award!

@steemitboard | Jan. 23, 2020, 10:10 p.m. | Votes: 0 | [ VOTE ]

Congratulations @branx! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@branx/birthday2.pngHappy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>