Calendar.OnVisibleMonthChanged(DateTime, DateTime) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 VisibleMonthChanged 控件的 Calendar 事件并使您可以为 VisibleMonthChanged 事件提供自定义处理程序。
protected:
virtual void OnVisibleMonthChanged(DateTime newDate, DateTime previousDate);
protected virtual void OnVisibleMonthChanged (DateTime newDate, DateTime previousDate);
abstract member OnVisibleMonthChanged : DateTime * DateTime -> unit
override this.OnVisibleMonthChanged : DateTime * DateTime -> unit
Protected Overridable Sub OnVisibleMonthChanged (newDate As DateTime, previousDate As DateTime)
参数
示例
下面的代码示例演示如何指定和编码 事件的处理程序 VisibleMonthChanged ,以显示 是向前移动还是 Calendar 向后移动一个月。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Calendar VisibleMonthChanged Example </title>
<script runat="server">
void MonthChange(Object sender, MonthChangedEventArgs e)
{
if (e.NewDate.Month > e.PreviousDate.Month)
{
Message.Text = "You moved forward one month.";
}
else
{
Message.Text = "You moved backwards one month.";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> Calendar VisibleMonthChanged Example </h3>
Select a different month on the calendar.
<br /><br />
<asp:Calendar id="Calendar1" runat="server"
OnVisibleMonthChanged="MonthChange">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:Silver">
<th>
Month navigation direction
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="Starting month."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Calendar VisibleMonthChanged Example </title>
<script runat="server">
Sub MonthChange(sender As Object, e As MonthChangedEventArgs)
If e.NewDate.Month > e.PreviousDate.Month Then
Message.Text = "You moved forward one month."
Else
Message.Text = "You moved backwards one month."
End If
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> Calendar VisibleMonthChanged Example </h3>
Select a different month on the calendar.
<br /><br />
<asp:Calendar id="Calendar1" runat="server"
OnVisibleMonthChanged="MonthChange">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:Silver">
<th>
Month navigation direction
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="Starting Month."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Calendar VisibleMonthChanged Example </title>
<script runat="server">
void MonthChange(Object sender, MonthChangedEventArgs e)
{
if (e.NewDate.Month > e.PreviousDate.Month)
{
Message.Text = "You moved forward one month.";
}
else
{
Message.Text = "You moved backwards one month.";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> Calendar VisibleMonthChanged Example </h3>
Select a different month on the calendar.
<br /><br />
<asp:Calendar id="Calendar1" runat="server"
OnVisibleMonthChanged="MonthChange">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:Silver">
<th>
Month navigation direction
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="Starting month."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Calendar VisibleMonthChanged Example </title>
<script runat="server">
Sub MonthChange(sender As Object, e As MonthChangedEventArgs)
If e.NewDate.Month > e.PreviousDate.Month Then
Message.Text = "You moved forward one month."
Else
Message.Text = "You moved backwards one month."
End If
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> Calendar VisibleMonthChanged Example </h3>
Select a different month on the calendar.
<br /><br />
<asp:Calendar id="Calendar1" runat="server"
OnVisibleMonthChanged="MonthChange">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:Silver">
<th>
Month navigation direction
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="Starting Month."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
VisibleMonthChanged当用户单击标题部分中的下一个月或上一个月的导航元素时,将引发 该事件。
引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件。
OnVisibleMonthChanged 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。
继承者说明
在派生类中重写 OnVisibleMonthChanged(DateTime, DateTime) 时,一定要调用基类的 OnVisibleMonthChanged(DateTime, DateTime) 方法,以便已注册的委托对事件进行接收。