CalendarDay Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta una data nel Calendar controllo .
public ref class CalendarDay
public class CalendarDay
type CalendarDay = class
Public Class CalendarDay
- Ereditarietà
-
CalendarDay
Esempio
Nell'esempio seguente viene illustrato come utilizzare le proprietà di un CalendarDay oggetto per determinare se la data di cui viene eseguito il rendering nell'evento DayRender si trova nel mese visualizzato e non rientra sabato o domenica. Queste date vengono visualizzate in giallo. Si noti che la Day proprietà dell'oggetto DayRenderEventArgs passato al DayRender gestore eventi è l'oggetto CalendarDay .
<%@ 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>
<title>ASP.NET Example</title>
<script language="C#" runat="server">
void DayRender(Object source, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
e.Cell.BackColor=System.Drawing.Color.Yellow;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Calendar id="calendar1" runat="server"
WeekendDayStyle-BackColor="gray"
OnDayRender="DayRender"/>
</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>
<title>ASP.NET Example</title>
<script language="VB" runat="server">
Sub DayRender(source As Object, e As DayRenderEventArgs)
If Not e.Day.IsOtherMonth And Not e.Day.IsWeekend Then
e.Cell.BackColor = System.Drawing.Color.Yellow
End If
End Sub 'DayRender
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Calendar id="calendar1" runat="server"
WeekendDayStyle-BackColor="gray"
OnDayRender="DayRender"/>
</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 DayRender Example</title>
<script runat="server">
void DayRender(Object sender, DayRenderEventArgs e)
{
// Change the background color of the days in the month
// to yellow.
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
{
e.Cell.BackColor=System.Drawing.Color.Yellow;
}
// Add custom text to cell in the Calendar control.
if (e.Day.Date.Day == 18)
{
e.Cell.Controls.Add(new LiteralControl("<br />Holiday"));
}
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the DayRender
// event of the Calendar control.
Calendar1.DayRender += new DayRenderEventHandler(this.DayRender);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</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 DayRender Example</title>
<script runat="server">
Sub DayRender(sender as Object, e As DayRenderEventArgs)
' Change the background color of the days in the month
' to yellow.
If (Not e.Day.IsOtherMonth) And (Not e.Day.IsWeekend) Then
e.Cell.BackColor=System.Drawing.Color.Yellow
End If
' Add custom text to cell in the Calendar control.
If e.Day.Date.Day = 18 Then
e.Cell.Controls.Add(New LiteralControl("<br />Holiday"))
End If
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
' Manually register the event-handling method for the DayRender
' event of the Calendar control.
AddHandler Calendar1.DayRender, AddressOf DayRender
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
Commenti
Un CalendarDay oggetto rappresenta una data nel Calendar controllo . È possibile utilizzare questa classe nel DayRender gestore eventi per accedere a livello di codice alle proprietà di una data durante il rendering nel Calendar controllo . In questo modo è possibile determinare le proprietà del giorno , ad esempio se la data è selezionabile, selezionata, la data di oggi o una data del fine settimana, e controllare a livello di codice l'aspetto o il comportamento del giorno.
Per un elenco dei valori iniziali delle proprietà per un'istanza di CalendarDay, vedere il costruttore CalendarDay.
Costruttori
| Nome | Descrizione |
|---|---|
| CalendarDay(DateTime, Boolean, Boolean, Boolean, Boolean, String) |
Inizializza una nuova istanza della classe CalendarDay. |
Proprietà
| Nome | Descrizione |
|---|---|
| Date |
Ottiene la data rappresentata da un'istanza di questa classe. Questa proprietà è di sola lettura. |
| DayNumberText |
Ottiene l'equivalente stringa del numero di giorno per la data rappresentata da un'istanza della CalendarDay classe . Questa proprietà è di sola lettura. |
| IsOtherMonth |
Ottiene un valore che indica se la data rappresentata da un'istanza di questa classe è in un mese diverso dal mese visualizzato nel Calendar controllo . Questa proprietà è di sola lettura. |
| IsSelectable |
Ottiene o imposta un valore che indica se la data rappresentata da un'istanza di questa classe può essere selezionata nel Calendar controllo . |
| IsSelected |
Ottiene un valore che indica se la data rappresentata da un'istanza di questa classe è selezionata nel Calendar controllo . Questa proprietà è di sola lettura. |
| IsToday |
Ottiene un valore che indica se la data rappresentata da un'istanza di questa classe corrisponde alla stessa data specificata dalla TodaysDate proprietà del Calendar controllo . Questa proprietà è di sola lettura. |
| IsWeekend |
Ottiene un valore che indica se la data rappresentata da un'istanza di questa classe è sabato o domenica. Questa proprietà è di sola lettura. |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |