PDA

View Full Version : سوال: طریقه تعیین ساعت و تاریخ کامپیوتر



muttahary21
جمعه 12 فروردین 1390, 11:44 صبح
من میخواهم مثلا یک برنامه بسازم که ساعت کامپیوتر را بتونه تغییر بده ممنون میشوم اگر کمک کنید

milad.biroonvand
جمعه 12 فروردین 1390, 12:04 عصر
سلام برای اینکار می تونی از کد زیر استفاده کنی




Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms


Public Class form1

Public Structure SYSTEMTIME
Public wYear As UInt16
Public wMonth As UInt16
Public wDayOfWeek As UInt16
Public wDay As UInt16
Public wHour As UInt16
Public wMinute As UInt16
Public wSecond As UInt16
Public wMilliseconds As UInt16
End Structure

Declare Function GetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32

Declare Function SetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32

Public Sub GetTime()
' Call the native GetSystemTime method
' with the defined structure.
Dim st As New SYSTEMTIME
GetSystemTime(st)

' Show the current time.
MessageBox.Show("Current Time: " & st.wHour.ToString() & ":" & st.wMinute.ToString())
End Sub

Public Sub SetTime()
' Call the native GetSystemTime method
' with the defined structure.
Dim st As New SYSTEMTIME
GetSystemTime(st)

' Set the system clock ahead one hour.
st.wDay = Convert.ToUInt16(((CInt(st.wDay) + 1)))
SetSystemTime(st)

End Sub





Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SetTime()
End Sub
End Class

milad.biroonvand
جمعه 12 فروردین 1390, 12:05 عصر
سلام

این کد از توابع api استفاده کرده با استفاده از دو تابع gettime و settime میتونی زمان رو تغییر بدی .