다음을 통해 공유


WebControl.Font 속성

정의

웹 서버 컨트롤과 연결된 글꼴 속성을 가져옵니다.

public:
 virtual property System::Web::UI::WebControls::FontInfo ^ Font { System::Web::UI::WebControls::FontInfo ^ get(); };
public virtual System.Web.UI.WebControls.FontInfo Font { get; }
member this.Font : System.Web.UI.WebControls.FontInfo
Public Overridable ReadOnly Property Font As FontInfo

속성 값

웹 서버 컨트롤의 글꼴 속성을 나타내는 A FontInfo 입니다.

예제

다음 예제에서는 컨트롤에서 글꼴 정보를 수집 하는 속성을 사용 Font 하는 방법을 보여 줍니다 Label .

메모

다음 코드 샘플에서는 단일 파일 코드 모델을 사용하며 코드 숨김 파일에 직접 복사한 경우 제대로 작동하지 않을 수 있습니다. 이 코드 샘플은 .aspx 확장이 있는 빈 텍스트 파일로 복사해야 합니다. Web Forms 코드 모델에 대한 자세한 내용은 ASP.NET Web Forms 페이지 코드 모델을 참조하세요.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
 
        void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "The current font is: " + Label1.Font.ToString();
        }

        void Button2_Click(object sender, EventArgs e)
        {
            Label1.Font.Underline = !Label1.Font.Underline;
            if (Label1.Font.Name == "Verdana")
                Label1.Font.Name = "Times";
            else
                Label1.Font.Name = "Verdana";
        }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Enabled Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>FontUnit Property of a Web Control</h3>
        <asp:Label id="Label1" runat="server"
            Font-Names="Verdana" Font-Size="10pt"
            Text="This is a Label control." />  
 
            <p>
            <asp:Button id="Button1" runat="server"
                Text="Click to display font info"
                OnClick="Button1_Click" Width="300px" />
            </p>
 
            <p>
            <asp:Button id="Button2" runat="server"
                Text="Click to change font and underlining"
                OnClick="Button2_Click" Width="300px" />
            </p>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Label1.Text = "The current font is: " & Label1.Font.ToString()
    End Sub

    Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
        Label1.Font.Underline = Not Label1.Font.Underline
        If Label1.Font.Name = "Verdana" Then
            Label1.Font.Name = "Times"
        Else
            Label1.Font.Name = "Verdana"
        End If
            
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Enabled Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>FontUnit Property of a Web Control</h3>
        <asp:Label id="Label1" runat="server"
            Font-Names="Verdana" Font-Size="10pt"
            Text="This is a Label control." />  
 
            <p>
            <asp:Button id="Button1" runat="server"
                Text="Click to display font info"
                OnClick="Button1_Click" Width="300px" />
            </p>
 
            <p>
            <asp:Button id="Button2" runat="server"
                Text="Click to change font and underlining"
                OnClick="Button2_Click" Width="300px" />
            </p>
    </div>
    </form>
</body>
</html>

설명

Font 이 속성을 사용하여 웹 서버 컨트롤의 글꼴 속성을 지정합니다. 이 속성에는 선언적으로(예: ) 형식 Property-Subproperty 으로 또는 프로그래밍 방식으로(예Font-BoldFont.Bold: ) 형식 Property.Subproperty 으로 액세스할 수 있는 하위 속성이 포함됩니다.

하나의 하위 속성만을 제외한 모든 컨트롤에 대해 Microsoft Internet Explorer 버전 4 이전의 브라우저에서 렌더링됩니다. 이러한 항목은 다음과 같습니다Bold. , Italic, NamesName, Strikeout, UnderlineSize (하지만 명명된 글꼴 크기(예: Small, Smaller등)만 작동합니다.)

메모

이러한 하위 속성은 Microsoft Internet Explorer 버전 4 이전의 브라우저에서 렌더링되지만 렌더링되는 HTML은 이후 브라우저와 다릅니다. 이러한 하위 속성은 스타일 특성으로 렌더링하는 대신 HTML 요소(예: 및 <font>.)로 <b> 렌더링됩니다.

모든 컨트롤에 대해 이전 브라우저에서 렌더링되지 않는 하나의 하위 속성은 다음과 같습니다 Overline.

적용 대상

추가 정보