HtmlImage.Width Propriedade

Definição

Obtém ou define a largura da imagem.Gets or sets the width of the image.

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

Valor da propriedade

Int32

A largura da imagem.The width of the image.

Exemplos

O exemplo de código a seguir demonstra como usar a Width propriedade para modificar programaticamente a largura da imagem exibida.The following code example demonstrates how to use the Width property to programmatically modify the width of the displayed image.

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

Comentários

As Height Width Propriedades e podem ser usadas de duas maneiras.The Height and Width properties can be used two ways. Você pode usar as Height Width Propriedades e para enviar as especificações de tamanho da imagem para o navegador.You can use the Height and Width properties to send the image size specifications to the browser. Isso exibe a página da Web mais rapidamente, pois o navegador não precisa recalcular as posições dos elementos na página quando a imagem é carregada.This displays the Web page faster because the browser does not need to recalculate the positions of elements on the page when the image loads.

Você também pode usar as Height Width Propriedades e para dimensionar a imagem.You can also use the Height and Width properties to scale the image. Ao usar valores que são diferentes do tamanho físico da imagem, a imagem é redimensionada de acordo.When using values that are different from the physical size of the image, the image is resized accordingly. No entanto, esse método de dimensionamento da imagem não é recomendado porque leva mais tempo para a página exibi-la.However, this method for scaling the image is not recommended because it takes longer for the page to display it. Em vez disso, redimensione fisicamente a imagem para o tamanho necessário.Instead, physically resize the image to the size you need.

Por padrão, a Width propriedade é expressa em pixels, mas também pode ser expressa como uma porcentagem do tamanho da janela.By default, the Width property is expressed in pixels, but it can also be expressed as a percentage of the window size.

Aplica-se a

Confira também