This documentation is archived and is not being maintained.
TableCell.HorizontalAlign Property
.NET Framework 1.1
Gets or sets the horizontal alignment of the contents in the cell.
[Visual Basic] Public Overridable Property HorizontalAlign As HorizontalAlign [C#] public virtual HorizontalAlign HorizontalAlign {get; set;} [C++] public: __property virtual HorizontalAlign get_HorizontalAlign(); public: __property virtual void set_HorizontalAlign(HorizontalAlign); [JScript] public function get HorizontalAlign() : HorizontalAlign; public function set HorizontalAlign(HorizontalAlign);
Property Value
One of the HorizontalAlign enumeration values. The default is NotSet.
Remarks
Use the HorizontalAlign property to specify the horizontal alignment of the contents of the cell. The following table lists the possible values.
| Horizontal Alignment | Description |
|---|---|
| NotSet | The horizontal alignment is not set. |
| Left | The contents of the cell are left justified. |
| Center | The contents of the cell are centered. |
| Right | The contents of the cell are right justified. |
| Justify | The contents of the cell are uniformly spread out and aligned with both the left and right margins. |
Example
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <HTML> <HEAD> <title>TableCell - VB.NET Example</title> <script runat="server"> Private Sub Page_Load(sender As Object, e As System.EventArgs) ' Create more rows for the table. Dim i As Integer For i = 2 To 9 Dim tempRow As New TableRow() Dim j As Integer For j = 0 To 2 Dim tempCell As New TableCell() tempCell.Text = "(" & i & "," & j & ")" tempCell.HorizontalAlign = HorizontalAlign.Center tempCell.VerticalAlign = VerticalAlign.Middle tempCell.RowSpan = 1 tempCell.Wrap = False tempRow.Cells.Add(tempCell) Next j Table1.Rows.Add(tempRow) Next i ' Create a header for the table. Dim header As New TableHeaderCell() header.RowSpan = 1 header.ColumnSpan = 3 header.Text = "Table of (x,y) Values" header.Font.Bold = true header.BackColor = System.Drawing.Color.CornflowerBlue header.HorizontalAlign = HorizontalAlign.Center header.VerticalAlign = VerticalAlign.Middle ' Add the header to a new row. Dim headerRow As New TableRow() headerRow.Cells.Add(header) ' Add the header row to the table. Table1.Rows.AddAt(0, headerRow) End Sub </script> </HEAD> <body> <form id="Form1" method="post" runat="server"> <h3>TableCell - VB.NET Example</h3> <asp:Table id="Table1" runat="server" CellPadding="3" CellSpacing="2" GridLines="Both" /> </form> </body> </HTML> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <HTML> <HEAD> <title>TableCell - C# Example</title> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { // Create more rows for the table. for (int i = 0; i < 10; i++) { TableRow tempRow = new TableRow(); for (int j = 0; j < 3; j++) { TableCell tempCell = new TableCell(); tempCell.Text = "(" + i + "," + j + ")"; tempCell.HorizontalAlign = HorizontalAlign.Center; tempCell.VerticalAlign = VerticalAlign.Middle; tempCell.RowSpan = 1; tempCell.Wrap = false; tempRow.Cells.Add(tempCell); } Table1.Rows.Add(tempRow); } // Create a header for the table. TableHeaderCell header = new TableHeaderCell(); header.RowSpan = 1; header.ColumnSpan = 3; header.Text = "Table of (x,y) Values"; header.Font.Bold = true; header.BackColor = System.Drawing.Color.CornflowerBlue; header.HorizontalAlign = HorizontalAlign.Center; header.VerticalAlign = VerticalAlign.Middle; // Add the header to a new row. TableRow headerRow = new TableRow(); headerRow.Cells.Add(header); // Add the header row to the table. Table1.Rows.AddAt(0, headerRow); } </script> </HEAD> <body> <form id="Form1" method="post" runat="server"> <h3>TableCell - C# Example</h3> <asp:Table id="Table1" runat="server" CellPadding="3" CellSpacing="2" GridLines="Both" /> </form> </body> </HTML>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
TableCell Class | TableCell Members | System.Web.UI.WebControls Namespace | HorizontalAlign | VerticalAlign
Show: