HtmlTableCell.BgColor プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlTableCell.BgColor プロパティの意味・解説 

HtmlTableCell.BgColor プロパティ

HtmlTableCell クラスのインスタンスが表すセルの背景色を取得または設定します。

名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説

BgColor プロパティを使用して、HtmlTableCell クラスのインスタンスが表すセルの背景色を指定します。色は、名前で指定するか、16 進値の前にシャープ記号 (#) を付けて #RRGGBB の形式で指定することができます。RR、GG、および BB はそれぞれ、色の赤、緑、および青の各要素を示す 0 ~ 255 の範囲の 16 進値を表します。たとえば、#0000FF という値は青を表します。この場合は、赤と緑の要素に最小値 (00) を指定し、青の要素に最大値 (FF) を指定しています。

BgColor プロパティに使用できる定義済みの 16 種類の HTML カラー名と、対応する 16 進値を次の表に示します。HTML カラーの詳細については、「World Wide Web Consortium (W3C) Web site」を参照してください。

カラー名

16 進値

水色

#00FFFF

黒

#000000

青

#0000FF

赤紫

#FF00FF

灰色

#808080

緑

#008000

ライム

#00FF00

茶

#800000

濃い青

#000080

オリーブ

#808000

紫

#800080

赤

#FF0000

シルバー

#C0C0C0

青緑

#008080

白

#FFFFFF

黄

#FFFF00

BgColor プロパティで使用できる色は、KnownColor 列挙体から判断できます。

カラー名では大文字と小文字は区別されません。

使用例使用例

BgColor プロパティを使用して、HtmlTable コントロールのセルの背景色をプログラムで制御するコード例を次に示します。

<%@ Page Language="VB" AutoEventWireup="True"
 %>

<script runat="server">

  Sub Button_Click(ByVal sender As
 Object, ByVal e As EventArgs)

    Dim i As Integer
    Dim j As Integer

    ' Iterate through the rows of the table.
    For i = 0 To Table1.Rows.Count - 1

      ' Iterate through the cells of a row.
      For j = 0 To Table1.Rows(i).Cells.Count
 - 1

        ' Update the properties of each cell. 
        Table1.Rows(i).Cells(j).BgColor = BgColorSelect.Value
        Table1.Rows(i).Cells(j).BorderColor = BorderColorSelect.Value
        Table1.Rows(i).Cells(j).Height = HeightSelect.Value
        Table1.Rows(i).Cells(j).Width = WidthSelect.Value
            
      Next j

    Next i

  End Sub

</script>

<html>
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             border="1" 
             bordercolor="black" 
             runat="server">

         <tr>
            <td>
               Cell 1.
            </td>
            <td>
               Cell 2.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>

      </table>

      <hr>

      Select the display settings for the cells
 in the table: <br><br>

      BgColor:
      <select id="BgColorSelect" 
              runat="server">

         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black">Black</option>
         <option value="White" selected>White</option>
        
      </select>

      &nbsp;&nbsp;

      BorderColor:
      <select id="BorderColorSelect" 
              runat="server">

         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black" selected>Black</option>
         <option value="White">White</option>

      </select>

      <br><br>

      Height:
      <select id="HeightSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="100">100</option>
         <option value="150">150</option>
         <option value="200">200</option>
         <option value="250">250</option>

      </select>

      &nbsp;&nbsp;

      Width:
      <select id="WidthSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="200">200</option>
         <option value="250">250</option>
         <option value="300">300</option>
         <option value="350">350</option>

      </select>
       
      <br><br>
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>

<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    // Iterate through the rows of the table.
    for (int i = 0; i <= Table1.Rows.Count
 - 1; i++)
    {

      // Iterate through the cells of a row.
      for (int j = 0; j <= Table1.Rows[i].Cells.Count
 - 1; j++)
      {
        // Update the properties of each cell. 
        Table1.Rows[i].Cells[j].BgColor = BgColorSelect.Value;
        Table1.Rows[i].Cells[j].BorderColor = BorderColorSelect.Value;
        Table1.Rows[i].Cells[j].Height = HeightSelect.Value;
        Table1.Rows[i].Cells[j].Width = WidthSelect.Value;
      }

    }

  }

</script>

<html>
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             border="1" 
             bordercolor="black" 
             runat="server">

         <tr>
            <td>
               Cell 1.
            </td>
            <td>
               Cell 2.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>

      </table>

      <hr>

      Select the display settings for the cells in
 the table: <br><br>

      BgColor:
      <select id="BgColorSelect" 
              runat="server">

         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black">Black</option>
         <option value="White" selected>White</option>
        
      </select>

      &nbsp;&nbsp;

      BorderColor:
      <select id="BorderColorSelect" 
              runat="server">

         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black" selected>Black</option>
         <option value="White">White</option>

      </select>

      <br><br>

      Height:
      <select id="HeightSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="100">100</option>
         <option value="150">150</option>
         <option value="200">200</option>
         <option value="250">250</option>

      </select>

      &nbsp;&nbsp;

      Width:
      <select id="WidthSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="200">200</option>
         <option value="250">250</option>
         <option value="300">300</option>
         <option value="350">350</option>

      </select>
       
      <br><br>
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlTableCell クラス
HtmlTableCell メンバ
System.Web.UI.HtmlControls 名前空間
HtmlTable クラス
BorderColor
Height
Width
KnownColor
その他の技術情報
HTML サーバー コントロール


このページでは「.NET Framework クラス ライブラリ リファレンス」からHtmlTableCell.BgColor プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHtmlTableCell.BgColor プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHtmlTableCell.BgColor プロパティ を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「HtmlTableCell.BgColor プロパティ」の関連用語

HtmlTableCell.BgColor プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlTableCell.BgColor プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS