MonthChangedEventHandler Delegasikan
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.
Mewakili metode yang menangani VisibleMonthChanged peristiwa Calendar kontrol.
public delegate void MonthChangedEventHandler(System::Object ^ sender, MonthChangedEventArgs ^ e);
public delegate void MonthChangedEventHandler(object sender, MonthChangedEventArgs e);
type MonthChangedEventHandler = delegate of obj * MonthChangedEventArgs -> unit
Public Delegate Sub MonthChangedEventHandler(sender As Object, e As MonthChangedEventArgs)
Parameter
- sender
- Object
Sumber dari peristiwa tersebut.
MonthChangedEventArgs yang berisi data peristiwa.
Contoh
Contoh kode berikut menunjukkan cara menentukan dan mengkodekan handler untuk VisibleMonthChanged peristiwa yang ditampilkan dalam Label kontrol apakah Calendar kontrol 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.";
}
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the
// VisibleMonthChanged event of the Calendar control.
Calendar1.VisibleMonthChanged +=
new MonthChangedEventHandler(this.MonthChange);
}
</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">
<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
Sub Page_Load(sender As Object, e As EventArgs)
' Manually register the event-handling method for the
' VisibleMonthChanged event of the Calendar control.
AddHandler Calendar1.VisibleMonthChanged, AddressOf MonthChange
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">
<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 kontrol navigasi agar Calendar kontrol ditampilkan pada bulan berikutnya atau sebelumnya.
Saat membuat MonthChangedEventHandler delegasi, Anda mengidentifikasi metode yang akan menangani peristiwa. Untuk mengaitkan peristiwa dengan penanganan aktivitas Anda, tambahkan instans delegasi ke peristiwa. Penanganan aktivitas dipanggil setiap kali peristiwa terjadi, kecuali Anda menghapus delegasi. Untuk informasi selengkapnya tentang delegasi penanganan aktivitas, lihat Menangani dan Menaikkan Peristiwa.
Metode Ekstensi
GetMethodInfo(Delegate) |
Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan. |