• 0

Programming in visual c#


Question

Hello to you all

i need to make a program that shutdown the PC in a specified time .........so pleas help me , i don't know how to get the time (hours,minutes and seconds ) from windows ....................

Thanx to you all....................................................

Link to comment
Share on other sites

Recommended Posts

  • 0
DateTime.Now will pull the time and date from the BIOS (which is set by windows)

thank you for answering me but i need the hours , the minutes and the seconds by it self i don't need the date

thank you againn

Link to comment
Share on other sites

  • 0

Sorry im a bit unsure I have absolutely no knowledge of C# minus bits i picked up from some fellow students at university :C

Edit: JediMark has it :)

Link to comment
Share on other sites

  • 0
DateTime.Now will pull the time and date from the BIOS (which is set by windows)

Thank you i found it, you can get the hours using this statement DateTime.Now.Hour

Link to comment
Share on other sites

  • 0
DateTime.Now will pull the time and date from the BIOS (which is set by windows)

I'm not sure if it is from the BIOS, but it is definitely the current system time

Datetime dt = new Datetime.Now;

also, what os are you doing this for? if its anything before xp, you'll probs have to mess about with importing the user32.dll (which you won't be able to add as a reference)

otherwise i think the System.Management namespace will be your friend :)

best of luck

Edited by BGM
Link to comment
Share on other sites

  • 0

Hello its me again............

i want to display a dynamic text or numbers in text box , like the time ..........................

pleas help thanx to you all .....................

Link to comment
Share on other sites

  • 0
Hello its me again............

i want to display a dynamic text or numbers in text box , like the time ..........................

pleas help thanx to you all .....................

do you mean like a ticking clock... the seconds changing?

Link to comment
Share on other sites

  • 0

well i think you didn't get my question , i am making a program that shutdown the pc after a interval of time , know i need to display in a text box for how many minutes the PC will shut down...............

Link to comment
Share on other sites

  • 0

Create a Windows Forms application, and using the designer drag a TextBox control onto it. Set its looks (size, fonts, colors etc) using the property editor in the designer. Then double click the form to get to the code editor in the form load event handler.

There, use timers to get the desired effect. Have the timer fire every second and when it fires, calculate how many seconds remain and set it to the .Text property of the text box.

const int shutDownAfter = 10000;	//in seconds
		int secondsElapsed = 0;

		private void MainForm_Load()
		{
			Timer t = new Timer() { Interval = 1000 /*Interval is calculated in ms*/ };
			t.Tick += (o, args) =>
			{
				textBox1.Text = new TimeSpan(0, 0, shutDownAfter - ++secondsElapsed).TotalMinutes.ToString("00.00");
				if (secondsElapsed == shutDownAfter)
				{
					t.Stop();
					ShutDown();
				}
			};
			t.Start();
		}

		private void ShutDown()
		{
			Process.Start(new ProcessStartInfo("shutdown.exe", "-s -f -p"));
		}

Or just do this in a cmd window ... that will display a countdown and shutdown the computer after the time elapses.

shutdown -s -f -t secondsToShutdownAfter -d "theReasonForShutdown"

Instead of -s, use -r to restart, -h to hibernate.

[Assuming .NET 3.5, Vista]

Link to comment
Share on other sites

  • 0
Create a Windows Forms application, and using the designer drag a TextBox control onto it. Set its looks (size, fonts, colors etc) using the property editor in the designer. Then double click the form to get to the code editor in the form load event handler.

There, use timers to get the desired effect. Have the timer fire every second and when it fires, calculate how many seconds remain and set it to the .Text property of the text box.

const int shutDownAfter = 10000;	//in seconds
		int secondsElapsed = 0;

		private void MainForm_Load()
		{
			Timer t = new Timer() { Interval = 1000 /*Interval is calculated in ms*/ };
			t.Tick += (o, args) =>
			{
				textBox1.Text = new TimeSpan(0, 0, shutDownAfter - ++secondsElapsed).TotalMinutes.ToString("00.00");
				if (secondsElapsed == shutDownAfter)
				{
					t.Stop();
					ShutDown();
				}
			};
			t.Start();
		}
thanx for your code but i want to display hoers minutes and seconds..................

		private void ShutDown()
		{
			Process.Start(new ProcessStartInfo("shutdown.exe", "-s -f -p"));
		}

Or just do this in a cmd window ... that will display a countdown and shutdown the computer after the time elapses.

shutdown -s -f -t secondsToShutdownAfter -d "theReasonForShutdown"

Instead of -s, use -r to restart, -h to hibernate.

[Assuming .NET 3.5, Vista]

thank you but i need to display the hours , minutes and seconds.....................??

i am using visual c# 2008

well i think you didn't get my question , i am making a program that shutdown the pc after a interval of time , know i need to display in a text box for how many minutes the PC will shut down............... so pleas help............

well i think you didn't get my question , i am making a program that shutdown the pc after a interval of time , know i need to display in a text box for how many minutes the PC will shut down...............

Link to comment
Share on other sites

  • 0
thank you but i need to display the hours , minutes and seconds.....................??

i am using visual c# 2008

well i think you didn't get my question , i am making a program that shutdown the pc after a interval of time , know i need to display in a text box for how many minutes the PC will shut down............... so pleas help............

well i think you didn't get my question , i am making a program that shutdown the pc after a interval of time , know i need to display in a text box for how many minutes the PC will shut down...............

t.Tick += (o, args) =>
			{
				var timespan = new TimeSpan(0, 0, shutDownAfter - ++secondsElapsed);
				textBox1.Text = String.Format("{0} hours {1} minutes and {2} seconds", timespan.Hours, timespan.Minutes, timespan.Seconds);
				if (secondsElapsed == shutDownAfter)
				{
					t.Stop();
					ShutDown();
				}
			};

Link to comment
Share on other sites

  • 0

Look guys i dint find anything about how to display a dynamic text in a text box, should i make a dynamic text box and how i can make it......!! , my problem is this :

i am making a program that shutdown the PC after a given time interval , what i need is to display in a text box for how hours minutes and seconds the PC will shutdown and i need to make a progress bar too............. so pleas help me i don't need a code i need to understand how i can make it work.................and i couldn't find a proper tutorial...................

Link to comment
Share on other sites

  • 0

What the hell do you not understand in the code?

Using the visual designer, drop a textbox onto the form. It will get a name like textBox1 or something. Rename if you want to. Set text formatting styles if you want to.

Then add text to it with this line of code:

textBox1.Text = <whatever text you want to display>

To replace the text, make another assignment with a different string

textBox1.Text = <some other text to replace the previous>

To get a ticking clock effect, update the textbox with the current time (or time elapsed or time remaining) every second.

And if you don't know anything about C# coding, pick up a beginner's book first.

Link to comment
Share on other sites

  • 0

hi soumyasch look i am a beginner look will this code display the time or not.........

private void timer3_Tick(object sender, EventArgs e)
		{
					   txetbox1.text= convert.tostring(timer2.tick);
	   }

???

Edited by Abood
Link to comment
Share on other sites

  • 0

If you can't even tell what the code you posted is, I'm afraid you're going to fail this assignment. You really need to start at "Hello World" and learn how events work. What you're asking for is a simple task, (and people have posted 90% of it.) If you're asking for someone to just write a program to do what you want, I believe there is a one-off jobs section here.

Link to comment
Share on other sites

  • 0

So guys !! no replay ,

pleas help..............................

i need to finish this for Monday ,

and i have a lote more work i need to make the pc shutdown after a process or process tree are done.......................

Link to comment
Share on other sites

  • 0
So guys any help.....................?? !!!

Abood, the guys in this thread have given you all the help you need to achieve your goal... I do not understand the problem(s) you are having?

perhaps a mod should just close this thread......?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.