本文介绍了如何在VB.NET中使用sendmessage API设置最小和最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i想要从所选年份设置datetimepicker的最小和最大日期。



提前付款



我尝试过:



我的代码:

Hii want to set min and max date of datetimepicker from selected year.

Thanks in Advance

What I have tried:

My Code:

Public Structure SYSTEMTIME
        Dim wYear As Integer
        Dim wMonth As Integer
        Dim wDayOfWeek As Integer
        Dim wDay As Integer
        Dim wHour As Integer
        Dim wMinute As Integer
        Dim wSecond As Integer
        Dim wMilliseconds As Integer

    End Structure

    Public Declare Function SendMessage Lib "user32.dll" _
                         Alias "SendMessageA" _
                         (ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Integer, ByVal lParam As SYSTEMTIME) As IntPtr
    Public Const DTM_SETRANGE = &H1004&
    Public Const GDTR_MIN = 1
    Public Const GDTR_MAX = 2

  Dim TimeArray(1) As SYSTEMTIME
        Dim result As IntPtr
        'Dim trdt As Date

        ' Define first minimum date.
        TimeArray(0).wDay = Format(dt, "dd")
        TimeArray(0).wMonth = Format(dt, "MM")
        TimeArray(0).wYear = Format(dt, "yyyy")

        ' Define second maximum date.
        TimeArray(1).wDay = Format(Dt1, "dd")
        TimeArray(1).wMonth = Format(Dt1, "MM")
        TimeArray(1).wYear = Format(Dt1, "yyyy")

        result = SendMessage(Me.dtpFrom.Handle, DTM_SETRANGE,
   GDTR_MIN + GDTR_MAX, TimeArray(0))



显示错误ror尝试读取或写入受保护的内存。这通常表明其他内存已损坏


Its showing error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt

推荐答案

Me.dtpFrom.MinDate = dt
Me.dtpFrom.MaxDate = dt1


这篇关于如何在VB.NET中使用sendmessage API设置最小和最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 15:32