任何人都可以帮助日历 [英] Can anyone can help with calendar

查看:113
本文介绍了任何人都可以帮助日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我想在我的应用程序中放入(Visual basic.net 2010)一个活动日历。

任何人都可以知道在哪里我找到了这个源代码。



提前谢谢

Hi guys

I want to put in my application (Visual basic.net 2010) an event Calendar.
Can anyone know where I find source code for this.

Thanks in advance

推荐答案

下面是一些代码片段我的一个程序。这不是一个完整的解决方案。它是使用 MonthCalendar Windows窗体控件的一种(多种)方式的示例,以允许用户输入和验证日期。此示例使用一个 MonthCalendar 控件并将其移动到通过关联的<$ c选择的 TextBox 旁边$ c>按钮控制。



到您的Windows窗体:

  • 添加MonthCalendar使用名为MonthCalendar的Visual Studio Windows窗体设计器对Windows窗体进行WinForms控制。
  • 为名为txtEffectiveDate的开始日期添加TextBox WinForms控件
  • 为名为txtExpirationDate的停止日期添加TextBox WinForms控件
  • 添加按钮WinForms控件以显示名为btnEffectiveDate的开始日期日历
  • 添加按钮WinForms控件以显示名为btnExpirationDate的停止日期日历
  • 添加按钮WinForms控件以完成名为btnOK的交易
Below are some code snippets from one of my programs. This is not a complete solution. It is an example of one (of many) way to use the MonthCalendar Windows Form control to allow user input and validation of dates. This example uses one MonthCalendar control and moves it to be next to the TextBox that is selected via the associated Button control.

To your Windows Form:
  • Add MonthCalendar WinForms control to your Windows Form using Visual Studio Windows Form Designer named MonthCalendar.
  • Add TextBox WinForms control for start date named txtEffectiveDate
  • Add TextBox WinForms control for stop date named txtExpirationDate
  • Add Button WinForms control to bring up calendar for Start date named btnEffectiveDate
  • Add Button WinForms control to bring up calendar for Stop date named btnExpirationDate
  • Add Button WinForms control to complete transaction named btnOK
' objTextbox is a reference to either the 
' txtEffectiveDate TextBox or the txtExpirationDate TextBox. 
' It is set in Click Event Handler
Dim objTextbox as Textbox 
Dim bError_EffectiveDate as Boolean ' True when Effective Date is invalid
Dim bError_ExpirationDate as Boolean ' True when Expiration Date is invalid



''选择日期的事件


'' Event for Date Selected

Private Sub MonthCalendar_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar.DateSelected
    bError_StartTime = False
    bError_StopTime = False
    objDateTextBox.Text = Format


(MonthCalendar.SelectionStart, MM / dd / yyyy
选择 案例 objDateTextBox.Name
案例 txtEffectiveDate
'
案例 txtExpirationDate
'
案例 < span class =code-keyword> Else
' 什么都不做
结束 选择
致电 ToggleCalendarButtons( True
btnOK.Enabled = True
txtStartTime.Focus ()
结束 Sub
(MonthCalendar.SelectionStart, "MM/dd/yyyy") Select Case objDateTextBox.Name Case "txtEffectiveDate" ' Case "txtExpirationDate" ' Case Else ' Do nothing End Select Call ToggleCalendarButtons(True) btnOK.Enabled = True txtStartTime.Focus() End Sub





''切换显示或隐藏MonthCalendar控件



'' Toggle show or hide the MonthCalendar control

Private Sub ToggleCalendarButtons(ByVal TRUEFALSE As Boolean)
    MonthCalendar.Visible = Not TRUEFALSE
    If Not TRUEFALSE Then
        MonthCalendar.BringToFront()
    End If
    btnEffectiveDate.Enabled = TRUEFALSE
    btnExpirationDate.Enabled = TRUEFALSE
    btnOK.Enabled = TRUEFALSE
    Try
        MonthCalendar.SetDate(CDate(objDateTextBox.Text))
    Catch
    End Try
    objDateTextBox.Focus()
End Sub





''处理生效日期和到期日期按钮的点击事件



'' Handle click event for Effective Date and Expiration Date buttons

Private Sub btnEffectiveDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEffectiveDate.Click
    btnEffectiveDate.Enabled = False
    If Not MonthCalendar.Visible Then
        MonthCalendar.Location = New Point(btnEffectiveDate.Location.X, btnEffectiveDate.Location.Y)
        objDateTextBox = txtEffectiveDate
        Call ToggleCalendarButtons(False)
    End If
    btnEffectiveDate.Enabled = True
End Sub

Private Sub btnExpirationDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExpirationDate.Click
    btnExpirationDate.Enabled = False
    If Not MonthCalendar.Visible Then
        MonthCalendar.Location = New Point(btnExpirationDate.Location.X, btnExpirationDate.Location.Y)
        objDateTextBox = txtExpirationDate
        Call ToggleCalendarButtons(False)
    End If
    btnExpirationDate.Enabled = True
End Sub



''验证日期以防万一使用键入它而不是从日历中选择


'' Validate date in case use keyed it instead of selecting from the calendar

Private Sub txtExpirationDate_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtExpirationDate.Validating
    If txtExpirationDate.Text.Length > 0 Then
        Try
            txtExpirationDate.Text = Format


CDate (txtExpirationDate.Text.ToString), MM / dd / yyyy
bError_ExpirationDate = False
Catch myException As InvalidCastException
MsgBox(myException.Message,MsgBoxStyle.Exclamation, 过期日期
bError_ExpirationDate = True
结束 尝试
结束 如果
En d Sub

私有 Sub txtEffectiveDate_Validating( ByVal sender As 对象 ByVal e As System.ComponentModel.CancelEventArgs)句柄 txtEffectiveDate.Validating
如果 txtEffectiveDate.Text.Length> 0 然后
尝试
txtEffectiveDate.Text =格式
(CDate(txtExpirationDate.Text.ToString), "MM/dd/yyyy") bError_ExpirationDate = False Catch myException As InvalidCastException MsgBox(myException.Message, MsgBoxStyle.Exclamation, "Expires Date") bError_ExpirationDate = True End Try End If End Sub Private Sub txtEffectiveDate_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtEffectiveDate.Validating If txtEffectiveDate.Text.Length > 0 Then Try txtEffectiveDate.Text = Format


这篇关于任何人都可以帮助日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆