DayRenderEventHandler 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public delegate void DayRenderEventHandler(System::Object ^ sender, DayRenderEventArgs ^ e);
public delegate void DayRenderEventHandler(object sender, DayRenderEventArgs e);
type DayRenderEventHandler = delegate of obj * DayRenderEventArgs -> unit
Public Delegate Sub DayRenderEventHandler(sender As Object, e As DayRenderEventArgs)
參數
- sender
- Object
事件的來源。
DayRenderEventArgs,其中包含事件資料。
範例
下列程式碼範例示範如何指定和撰寫事件的處理常式 DayRender ,使顯示月份中的天數背景色彩變成黃色。 它也會示範如何將控制項新增 System.Web.UI.LiteralControl 至儲存格,來自訂儲存格的內容。
<%@ 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>DayRender Event Example</title>
<script language="C#" runat="server">
void DayRender(Object source, 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"));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>DayRender Event Example</h3>
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
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>
<title>DayRender Event Example</title>
<script language="VB" runat="server">
Sub DayRender(source 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(ChrW(60) & "br" & ChrW(62) & "Holiday"))
End If
End Sub 'DayRender
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>DayRender Event Example</h3>
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</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>
備註
雖然控制項不支援 Calendar 資料系結,但可以修改個別日期儲存格的內容和格式設定。 Calendar在控制項顯示在網頁上之前,它會建立並組合組成控制項的元件。 建立 DayRender 控制項中的每個 Calendar 日期資料格時,就會引發事件。 您可以在事件事件處理常式 DayRender 中提供程式碼,來控制日期儲存格的內容和格式設定。 如需自訂日期儲存格內容的詳細資訊,請參閱 OnDayRender 。
建立 DayRenderEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理常式委派的詳細資訊,請參閱 處理和引發事件。
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |