HtmlImage.Height Właściwość

Definicja

Pobiera lub ustawia wysokość obrazu.

public:
 property int Height { int get(); void set(int value); };
public int Height { get; set; }
member this.Height : int with get, set
Public Property Height As Integer

Wartość właściwości

Int32

Wysokość obrazu.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą Height właściwości programowo zmodyfikować wysokość wyświetlanego obrazu.

<%@ 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>HtmlImage Example</title>
<script language="C#" runat="server">
        
       void Button_Click1(object sender, EventArgs e) 
       {
          Image1.Height=500;
          Image1.Width=1000;
       }
    
       void Button_Click2(object sender, EventArgs e) 
       {
          Image1.Height=226;
          Image1.Width=500;
       }
 
    </script>
 
 </head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
       <br /><br />
       <button id="Button1"
               onserverclick="Button_Click1"
               runat="server">
       Zoom Image
       </button>
       <button id="Button2"
               onserverclick="Button_Click2"
               runat="server">
       Normal Size
       </button>
    
    </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>HtmlImage Example</title>
<script language="VB" runat="server">
        
    Sub Button_Click1(sender As Object, e As EventArgs)
        Image1.Height = 500
        Image1.Width = 1000
    End Sub 'Button_Click1


    Sub Button_Click2(sender As Object, e As EventArgs)
        Image1.Height = 226
        Image1.Width = 500
    End Sub 'Button_Click2
 
  </script>
 
 </head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
       <br /><br />
       <button id="Button1"
               onserverclick="Button_Click1"
               runat="server">
       Zoom Image
       </button>
       <button id="Button2"
               onserverclick="Button_Click2"
               runat="server">
       Normal Size
       </button>
    
    </form>
 
 </body>
 </html>

Uwagi

Właściwości Height i Width można używać na dwa sposoby. Właściwości i Width umożliwiają Height wysyłanie specyfikacji rozmiaru obrazu do przeglądarki. Spowoduje to szybsze wyświetlenie strony sieci Web, ponieważ przeglądarka nie musi ponownie obliczać pozycji elementów na stronie podczas ładowania obrazu.

Można również użyć Height właściwości i Width do skalowania obrazu. W przypadku używania wartości innych niż rozmiar fizyczny obrazu zmienia się odpowiednio rozmiar obrazu. Jednak ta metoda skalowania obrazu nie jest zalecana, ponieważ wyświetlanie go trwa dłużej. Zamiast tego fizycznie zmień rozmiar obrazu na potrzebny rozmiar.

Domyślnie Height właściwość jest wyrażona w pikselach, ale może być również wyrażona jako wartość procentowa rozmiaru okna.

Dotyczy

Zobacz też