Write a timer using C # (original)

xiaoxiao2021-03-06  65

Hello everyone! I haven't come up for a long time! Little sonance hello to all directions! Today, I'm taking a charm of C #, solved a problem with the boss. I always don't understand the heavy-duty operator. I don't know what it is useful. Today, I will use it to use it. I really use it in the deep mountain linger. Feel, huh, huh! I used it to make a timer. I will put the code from the code to everyone! First let's talk about: 1. Built a Windows application with .NET 2. Add a class to "Time" under the project. Write "Time" class to implement code 4. Put two Label controls in the form And a clock control 5. Write a TIMER TIAD Event and (Timer) Tick Events The following is the "Time" class implement code: public class time {private int hours; // hour private int minutes; // Minute int seconds; // second public time () {this.Hours = 0; this.minutes = 0; this.seconds = 0;}

Public Time (int Hours, int minutes, int specials) {this.Hours = Hours; this.minutes = minutes;} = seconds;}

Public void sethours (int hours) {this.hairs = Hours;

Public void setminutes (int minutes) {this.minutes = minutes;

Public void setseconds (int specials) {this.seconds = seconds;}

Public int gethours () {return this.Hours;

Public int getminutes () {returnim

Public int getseconds () {return this.seconds;}

Public Static Time Operator (Time Time) {TIME.SECONDS ; if (Time.Seconds> = 60) {Time.minutes ; Time.Seconds = 0; if (Time.minutes> = 60) {Time.Hours ; Time .minutes = 0; time.seconds = 0; if (time.hours> = 24) {time.Hours = 0; time.minutes = 0; time.seconds = 0;}}}}}}} return new time (Time. Hours, Time.minutes, time.seconds;}}}}}} The following is a Tick event handler for the LOAD event and Timer control: private void form1_load (object sender, system.eventargs e) {datetime dtime = datetime.now; int hour = DTIME. HOUR INT minute = dtime.minute; int second = dtime.second; time = new time (hour, minute, second); this.label1.text = "The current time is:" Hour ":" minute ": " Second; this.timer1.start ();} private sender, system.eventargs e) {time ; this.label2.text =" time lapse: " Time.GetHours () ": ":" Time.getminutes () ":" Time.getSeconds ();} Time is limited, running!

转载请注明原文地址:https://www.9cbs.com/read-85385.html

New Post(0)