Calendar.OnVisibleMonthChanged(DateTime, DateTime) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
VisibleMonthChanged Meningkatkan peristiwa Calendar kontrol dan memungkinkan Anda menyediakan handler kustom untuk peristiwa tersebutVisibleMonthChanged.
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)
Parameter
Contoh
Contoh kode berikut menunjukkan cara menentukan dan mengkodekan handler untuk peristiwa guna VisibleMonthChanged menampilkan apakah Calendar telah bergerak maju atau mundur satu bulan.
<%@ 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>
Keterangan
Peristiwa VisibleMonthChanged dimunculkan saat pengguna mengklik elemen navigasi bulan berikutnya atau sebelumnya di bagian judul.
Menaikkan peristiwa memanggil penanganan aktivitas melalui delegasi. Untuk informasi selengkapnya, lihat Menangani dan Menaikkan Peristiwa.
Metode ini OnVisibleMonthChanged juga memungkinkan kelas turunan untuk menangani peristiwa tanpa melampirkan delegasi. Ini adalah teknik yang disukai untuk menangani peristiwa di kelas turunan.
Catatan Bagi Inheritor
Saat mengambil alih di kelas turunan OnVisibleMonthChanged(DateTime, DateTime) , pastikan untuk memanggil metode kelas OnVisibleMonthChanged(DateTime, DateTime) dasar sehingga delegasi terdaftar menerima peristiwa tersebut.