Calendar.OnVisibleMonthChanged(DateTime, DateTime) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Gera o evento VisibleMonthChanged do controle Calendar e permite que você forneça um manipulador personalizado para o evento 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)
Parâmetros
Exemplos
O exemplo de código a seguir demonstra como especificar e codificar um manipulador para o VisibleMonthChanged evento para exibir se o Calendar avançou ou retrocedeu um mês.
<%@ 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>
Comentários
O VisibleMonthChanged evento é gerado quando o usuário clica nos elementos de navegação do mês seguinte ou anterior na seção título.
A geração de um evento invoca o manipulador de eventos por meio de um delegado. Para obter mais informações, consulte Manipulando e levantando eventos.
O OnVisibleMonthChanged método também permite que classes derivadas manipulem o evento sem anexar um delegado. Essa é a técnica preferencial para lidar com o evento em uma classe derivada.
Notas aos Herdeiros
Ao substituir OnVisibleMonthChanged(DateTime, DateTime) em uma classe derivada, chame o método da OnVisibleMonthChanged(DateTime, DateTime) classe base para que os delegados registrados recebam o evento.