Bagikan melalui


WebControl.Font Properti

Definisi

Mendapatkan properti font yang terkait dengan kontrol server Web.

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

Nilai Properti

FontInfo yang mewakili properti font kontrol server Web.

Contoh

Contoh berikut mengilustrasikan cara menggunakan Font properti untuk mengumpulkan informasi font dari Label kontrol.

Catatan

Sampel kode berikut menggunakan model kode file tunggal dan mungkin tidak berfungsi dengan benar jika disalin langsung ke file code-behind. Sampel kode ini harus disalin ke dalam file teks kosong yang memiliki ekstensi .aspx. Untuk informasi selengkapnya tentang model kode Formulir Web, lihat Model Kode Halaman Formulir Web ASP.NET.

<%@ 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>

Keterangan

Font Gunakan properti untuk menentukan properti font kontrol Server Web. Properti ini mencakup subproperti yang dapat diakses secara deklaratif dalam bentuk Property-Subproperty (misalnya Font-Bold) atau secara terprogram dalam bentuk Property.Subproperty (misalnya Font.Bold).

Semua kecuali satu subproperti akan dirender di browser sebelum Microsoft Internet Explorer versi 4 untuk semua kontrol. Mereka adalah: Bold, , Italic, NamesName, Strikeout, Underlinedan Size (tetapi hanya ukuran font bernama, seperti , , Smallerdan sebagainyaSmall, akan berfungsi).

Catatan

Meskipun subproperti ini dirender di browser sebelum Microsoft Internet Explorer versi 4, HTML yang dirender berbeda dari browser yang lebih baru. Alih-alih merender sebagai atribut gaya, subproperti ini dirender sebagai elemen HTML, seperti <b> dan <font>.

Satu subproperti yang tidak akan dirender di browser sebelumnya untuk semua kontrol adalah Overline.

Berlaku untuk

Lihat juga