In the form, i have a datetimepicker tool, and 2 button. So, my question is, which code can i shut down the pc, and how can i read the selected time from the datetimepicker ( which is set to time ( h/m ) ) ?
The code is currently:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Short;
dateTimePicker1.Value = DateTime.Today;
}
private void button1_Click(object sender, EventArgs e)
{
DateTime iDate;
iDate = dateTimePicker1.Value;
MessageBox.Show("A kiválasztott dátum: " + iDate);
}
private void button2_Click(object sender, EventArgs e)
{
DateTime iDate;
iDate = dateTimePicker1.Value;
MessageBox.Show("A kiválasztott dátum: " + iDate);
}
}
}
Santhosh Kumar JayaramanPosted Jan 8, 2013, 12:25 PM
Add System.Diagnostics for reference
ProcessStartInfo startinfo = new ProcessStartInfo("shutdown.exe", "-s");
Process.Start(startinfo);
To ShutDown : shutdown -s
To Restart : shutdown -r
To Logoff : shutdown -l
To Hibernate :%windir%\system32\rundll32.exe PowrProf.dll,SetSuspendState
To Lock : Rundll32.exe User32.dll,LockWorkStation
To Sleep : rundll32.exe powrprof.dll,SetSuspendState 0,1,0
to get time from datetimepicker
datetimepicker1.ToString("hh:mm");