DoboWiki
Top
> .NETプログラミング研究/70 をテンプレートにして作成
.NETプログラミング研究/70 をテンプレートにして作成
開始行:
#title(.NETプログラミング研究 第70号)
#navi(.NETプログラミング研究)
#contents
*.NETプログラミング研究 第70号 [#fa28542b]
**.NET Tips [#zb701478]
今回は前回の続きです。.NET Framework 2.0から追加されたWin...
前回紹介した、TableLayoutPanelを使ったサンプル、「TableLa...
-[[TableLayoutPanelコントロールの基本的な使い方>https://d...
***セルの行または列を拡大する [#ibca28df]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelのセルの行または列...
}}
フォームデザイナによる方法が、MSDNの次のページで説明され...
-[[方法 : TableLayoutPanel コントロールの行と列を拡大する...
これによると、TableLayoutPanelコントロールのセルの行また...
実際には、TableLayoutPanel.SetRowSpanとSetColumnSpanメソ...
次のコードでは、tableLayoutPanel1に配置されたcurrentContr...
#code(vbnet){{
Dim newColSpan As Integer = _
TableLayoutPanel1.GetColumnSpan(currentControl) + 1
'テーブルの列の数より大きくなることをさける
'SetColumnSpanでテーブルの列の数より大きい値を設定できる...
If TableLayoutPanel1.ColumnCount >= _
TableLayoutPanel1.GetColumn(currentControl) + newColS...
TableLayoutPanel1.SetColumnSpan(currentControl, newCo...
End If
}}
#code(csharp){{
int newColSpan = tableLayoutPanel1.GetColumnSpan(currentC...
//テーブルの列の数より大きくなることをさける
//SetColumnSpanでテーブルの列の数より大きい値を設定できる...
if (tableLayoutPanel1.ColumnCount >=
tableLayoutPanel1.GetColumn(currentControl) + newColS...
{
tableLayoutPanel1.SetColumnSpan(currentControl, newCo...
}
}}
サンプル「TableLayoutPanel1.exe」では、コントロールを右ク...
***AnchorとDockプロパティ [#d63de17c]
TableLayoutPanelもFlowLayoutPanelと同様に、配置された子コ...
-[[方法 : TableLayoutPanel コントロールで子コントロールを...
サンプル「TableLayoutPanel1.exe」では、コントロールを右ク...
***行と列のスタイルを変更する [#b9777a46]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行と列のスタイル...
}}
MSDNでは、「方法 : TableLayoutPanel コントロールの列と行...
-[[方法 : TableLayoutPanel コントロールの列と行を編集する...
フォームデザイナを使った方法では、TableLayoutPanelのRows...
しかし実際にはTableLayoutPanelクラスにRowsやColumnsプロパ...
例えば、一行目のサイズの型を絶対サイズの50ピクセルとする...
#code(vbnet){{
TableLayoutPanel1.RowStyles(0) = New RowStyle(SizeType.Ab...
}}
#code(csharp){{
tableLayoutPanel1.RowStyles[0] = new RowStyle(SizeType.Ab...
}}
ただし、RowStylesとColumnStylesはあくまでスタイル(サイズ...
「列と行のスタイル」ダイアログのみで列(あるいは行)を管...
注意:デザイナで列や行を増やした時は問題ありませんが、減...
しかし、デザイナを使わないで列や行の数を変更した場合は、...
その意味で、先ほど示した例も、tableLayoutPanel1.RowStyles...
#code(vbnet){{
'スタイルを変更する行数
Dim rowIndex As Integer = 4
'スタイル
Dim rs As New RowStyle(SizeType.Absolute, 50.0F)
If TableLayoutPanel1.RowStyles.Count > rowIndex Then
TableLayoutPanel1.RowStyles(rowIndex) = rs
Else
'とりあえずRowStyleを埋める
While TableLayoutPanel1.RowStyles.Count < rowIndex
TableLayoutPanel1.RowStyles.Add( _
New RowStyle(SizeType.AutoSize))
End While
TableLayoutPanel1.RowStyles.Add(rs)
End If
}}
#code(csharp){{
//スタイルを変更する行数
int rowIndex = 4;
//スタイル
RowStyle rs = new RowStyle(SizeType.Absolute, 50F);
if (tableLayoutPanel1.RowStyles.Count > rowIndex)
{
tableLayoutPanel1.RowStyles[rowIndex] = rs;
}
else
{
//とりあえずRowStyleを埋める
while (tableLayoutPanel1.RowStyles.Count < rowIndex)
{
tableLayoutPanel1.RowStyles.Add(
new RowStyle(SizeType.AutoSize));
}
tableLayoutPanel1.RowStyles.Add(rs);
}
}}
***行や列を挿入する [#ue3c2bba]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行や列を挿入する>...
}}
「列と行のスタイル」ダイアログを使えば行や列の挿入は簡単...
しかし単純にそのようなコードを書いたとしてもうまくいくと...
よってここでは、先に紹介したように、TableLayoutPanelに配...
以下の例では、insertRowの位置に行を挿入しています。サンプ...
#code(vbnet){{
TableLayoutPanel1.SuspendLayout()
Dim c As Control
For Each c In TableLayoutPanel1.Controls
Dim pos As TableLayoutPanelCellPosition = _
TableLayoutPanel1.GetPositionFromControl(c)
TableLayoutPanel1.SetCellPosition(c, pos)
If TableLayoutPanel1.RowCount <= pos.Row Then
TableLayoutPanel1.RowCount = pos.Row + 1
End If
If TableLayoutPanel1.ColumnCount <= pos.Column Then
TableLayoutPanel1.ColumnCount = pos.Column + 1
End If
Next c
'列を増やす
TableLayoutPanel1.RowCount += 1
'コントロールを移動
Dim y As Integer
For y = TableLayoutPanel1.RowCount - 1 To insertRow Step -1
Dim x As Integer
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, y)
If Not (c Is Nothing) Then
TableLayoutPanel1.SetCellPosition( _
c, New TableLayoutPanelCellPosition(x, y ...
End If
Next x
Next y
'スタイルを挿入
If TableLayoutPanel1.RowStyles.Count > insertRow Then
TableLayoutPanel1.RowStyles.Insert( _
insertRow, New RowStyle(SizeType.AutoSize))
End If
TableLayoutPanel1.ResumeLayout()
}}
#code(csharp){{
tableLayoutPanel1.SuspendLayout();
foreach (Control c in tableLayoutPanel1.Controls)
{
TableLayoutPanelCellPosition pos =
tableLayoutPanel1.GetPositionFromControl(c);
tableLayoutPanel1.SetCellPosition(c, pos);
if (tableLayoutPanel1.RowCount <= pos.Row)
tableLayoutPanel1.RowCount = pos.Row + 1;
if (tableLayoutPanel1.ColumnCount <= pos.Column)
tableLayoutPanel1.ColumnCount = pos.Column + 1;
}
//列を増やす
tableLayoutPanel1.RowCount++;
//コントロールを移動
for (int y = tableLayoutPanel1.RowCount - 1; y >= insertR...
{
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosit...
if (c != null)
{
tableLayoutPanel1.SetCellPosition(
c, new TableLayoutPanelCellPosition(x, y ...
}
}
}
//スタイルを挿入
if (tableLayoutPanel1.RowStyles.Count > insertRow)
{
tableLayoutPanel1.RowStyles.Insert(
insertRow, new RowStyle(SizeType.AutoSize));
}
tableLayoutPanel1.ResumeLayout();
}}
***行や列を削除する [#ja25e47e]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行や列を削除する>...
}}
これもやはりうまい方法がありませんが、前と同じ方針で行っ...
以下の例では、removeRowの位置の行を削除しています。サンプ...
#code(vbnet){{
TableLayoutPanel1.SuspendLayout()
Dim c As Control
For Each c In TableLayoutPanel1.Controls
Dim pos As TableLayoutPanelCellPosition = _
TableLayoutPanel1.GetPositionFromControl(c)
TableLayoutPanel1.SetCellPosition(c, pos)
If TableLayoutPanel1.RowCount <= pos.Row Then
TableLayoutPanel1.RowCount = pos.Row + 1
End If
If TableLayoutPanel1.ColumnCount <= pos.Column Then
TableLayoutPanel1.ColumnCount = pos.Column + 1
End If
Next c
'削除する列にあるコントロールを削除
Dim x As Integer
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, remov...
If Not (c Is Nothing) Then
TableLayoutPanel1.Controls.Remove(c)
End If
Next x
'コントロールを移動
Dim y As Integer
For y = removeRow + 1 To TableLayoutPanel1.RowCount - 1
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, y)
If Not (c Is Nothing) Then
TableLayoutPanel1.SetCellPosition( _
c, New TableLayoutPanelCellPosition(x, y ...
End If
Next x
Next y
'列を減らす
If TableLayoutPanel1.RowCount > 0 Then
TableLayoutPanel1.RowCount -= 1
End If
'スタイルを削除
If TableLayoutPanel1.RowStyles.Count > removeRow Then
TableLayoutPanel1.RowStyles.RemoveAt(removeRow)
End If
TableLayoutPanel1.ResumeLayout()
}}
#code(csharp){{
tableLayoutPanel1.SuspendLayout();
foreach (Control c in tableLayoutPanel1.Controls)
{
TableLayoutPanelCellPosition pos =
tableLayoutPanel1.GetPositionFromControl(c);
tableLayoutPanel1.SetCellPosition(c, pos);
if (tableLayoutPanel1.RowCount <= pos.Row)
tableLayoutPanel1.RowCount = pos.Row + 1;
if (tableLayoutPanel1.ColumnCount <= pos.Column)
tableLayoutPanel1.ColumnCount = pos.Column + 1;
}
//削除する列にあるコントロールを削除
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosition(...
if (c != null)
{
tableLayoutPanel1.Controls.Remove(c);
}
}
//コントロールを移動
for (int y = removeRow + 1; y < tableLayoutPanel1.RowCoun...
{
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosit...
if (c != null)
{
tableLayoutPanel1.SetCellPosition(
c, new TableLayoutPanelCellPosition(x, y ...
}
}
}
//列を減らす
if (tableLayoutPanel1.RowCount > 0)
tableLayoutPanel1.RowCount--;
//スタイルを削除
if (tableLayoutPanel1.RowStyles.Count > removeRow)
{
tableLayoutPanel1.RowStyles.RemoveAt(removeRow);
}
tableLayoutPanel1.ResumeLayout();
}}
このように、実行時にTableLayoutPanelに行や列を挿入あるい...
***セルを独自に描画する [#i0b8cefe]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelのセルを独自に描画...
}}
TableLayoutPanelのCellPaintイベントにより、セルを独自に描...
次の例では、一つおきのセルに色をつけています。サンプル「T...
#code(vbnet){{
'TableLayoutPanel1のCellPaintイベントハンドラ
Private Sub TableLayoutPanel1_CellPaint( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TableLayoutCellPaintE...
Handles TableLayoutPanel1.CellPaint
'一つおきにセルの背景色を変更する
If (e.Column Mod 2 = 1) Xor (e.Row Mod 2 = 1) Then
e.Graphics.FillRectangle(Brushes.LightSkyBlue, e....
End If
End Sub
}}
#code(csharp){{
//tableLayoutPanel1のCellPaintイベントハンドラ
void tableLayoutPanel1_CellPaint(object sender,
TableLayoutCellPaintEventArgs e)
{
//一つおきにセルの背景色を変更する
if (e.Column % 2 == 1 ^ e.Row % 2 == 1)
{
e.Graphics.FillRectangle(Brushes.LightSkyBlue, e....
}
}
}}
***継承したコントロールでデザイナを使ってFlowLayoutPanel...
#column(注意){{
この記事の最新版は「[[継承したコントロールでデザイナを使...
}}
FlowLayoutPanelを配置したコントロール(フォームを含む)を...
-[[Bug Details: Form designer doesn’t allow to modify pro...
FlowLayoutPanelについての解決法が次のページで紹介されてい...
-[[FDBK37485#1: Can manage to use FlowLayoutPanel with so...
これによると、FlowLayoutPanelを継承したクラスを作成し、こ...
つまり、例えばまず次のようなクラスを作成し、
#code(vbnet){{
<System.ComponentModel.Designer( _
"System.Windows.Forms.Design.PanelDesigner, System.Design...
Public Class InheritableFlowLayoutPanel
Inherits FlowLayoutPanel
Public Sub New()
End Sub
End Class
}}
#code(csharp){{
[Designer("System.Windows.Forms.Design.PanelDesigner, Sys...
public class InheritableFlowLayoutPanel : FlowLayoutPanel
{
public InheritableFlowLayoutPanel()
{
}
}
}}
これをFlowLayoutPanelの代わりに使うようにします。
残念ながらこれはFlowLayoutPanelだけの解決法で、TableLayou...
**コメント [#r099905e]
#comment
//これより下は編集しないでください
#pageinfo([[:Category/.NET]],2006-06-05 (月) 06:00:00,DOB...
終了行:
#title(.NETプログラミング研究 第70号)
#navi(.NETプログラミング研究)
#contents
*.NETプログラミング研究 第70号 [#fa28542b]
**.NET Tips [#zb701478]
今回は前回の続きです。.NET Framework 2.0から追加されたWin...
前回紹介した、TableLayoutPanelを使ったサンプル、「TableLa...
-[[TableLayoutPanelコントロールの基本的な使い方>https://d...
***セルの行または列を拡大する [#ibca28df]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelのセルの行または列...
}}
フォームデザイナによる方法が、MSDNの次のページで説明され...
-[[方法 : TableLayoutPanel コントロールの行と列を拡大する...
これによると、TableLayoutPanelコントロールのセルの行また...
実際には、TableLayoutPanel.SetRowSpanとSetColumnSpanメソ...
次のコードでは、tableLayoutPanel1に配置されたcurrentContr...
#code(vbnet){{
Dim newColSpan As Integer = _
TableLayoutPanel1.GetColumnSpan(currentControl) + 1
'テーブルの列の数より大きくなることをさける
'SetColumnSpanでテーブルの列の数より大きい値を設定できる...
If TableLayoutPanel1.ColumnCount >= _
TableLayoutPanel1.GetColumn(currentControl) + newColS...
TableLayoutPanel1.SetColumnSpan(currentControl, newCo...
End If
}}
#code(csharp){{
int newColSpan = tableLayoutPanel1.GetColumnSpan(currentC...
//テーブルの列の数より大きくなることをさける
//SetColumnSpanでテーブルの列の数より大きい値を設定できる...
if (tableLayoutPanel1.ColumnCount >=
tableLayoutPanel1.GetColumn(currentControl) + newColS...
{
tableLayoutPanel1.SetColumnSpan(currentControl, newCo...
}
}}
サンプル「TableLayoutPanel1.exe」では、コントロールを右ク...
***AnchorとDockプロパティ [#d63de17c]
TableLayoutPanelもFlowLayoutPanelと同様に、配置された子コ...
-[[方法 : TableLayoutPanel コントロールで子コントロールを...
サンプル「TableLayoutPanel1.exe」では、コントロールを右ク...
***行と列のスタイルを変更する [#b9777a46]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行と列のスタイル...
}}
MSDNでは、「方法 : TableLayoutPanel コントロールの列と行...
-[[方法 : TableLayoutPanel コントロールの列と行を編集する...
フォームデザイナを使った方法では、TableLayoutPanelのRows...
しかし実際にはTableLayoutPanelクラスにRowsやColumnsプロパ...
例えば、一行目のサイズの型を絶対サイズの50ピクセルとする...
#code(vbnet){{
TableLayoutPanel1.RowStyles(0) = New RowStyle(SizeType.Ab...
}}
#code(csharp){{
tableLayoutPanel1.RowStyles[0] = new RowStyle(SizeType.Ab...
}}
ただし、RowStylesとColumnStylesはあくまでスタイル(サイズ...
「列と行のスタイル」ダイアログのみで列(あるいは行)を管...
注意:デザイナで列や行を増やした時は問題ありませんが、減...
しかし、デザイナを使わないで列や行の数を変更した場合は、...
その意味で、先ほど示した例も、tableLayoutPanel1.RowStyles...
#code(vbnet){{
'スタイルを変更する行数
Dim rowIndex As Integer = 4
'スタイル
Dim rs As New RowStyle(SizeType.Absolute, 50.0F)
If TableLayoutPanel1.RowStyles.Count > rowIndex Then
TableLayoutPanel1.RowStyles(rowIndex) = rs
Else
'とりあえずRowStyleを埋める
While TableLayoutPanel1.RowStyles.Count < rowIndex
TableLayoutPanel1.RowStyles.Add( _
New RowStyle(SizeType.AutoSize))
End While
TableLayoutPanel1.RowStyles.Add(rs)
End If
}}
#code(csharp){{
//スタイルを変更する行数
int rowIndex = 4;
//スタイル
RowStyle rs = new RowStyle(SizeType.Absolute, 50F);
if (tableLayoutPanel1.RowStyles.Count > rowIndex)
{
tableLayoutPanel1.RowStyles[rowIndex] = rs;
}
else
{
//とりあえずRowStyleを埋める
while (tableLayoutPanel1.RowStyles.Count < rowIndex)
{
tableLayoutPanel1.RowStyles.Add(
new RowStyle(SizeType.AutoSize));
}
tableLayoutPanel1.RowStyles.Add(rs);
}
}}
***行や列を挿入する [#ue3c2bba]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行や列を挿入する>...
}}
「列と行のスタイル」ダイアログを使えば行や列の挿入は簡単...
しかし単純にそのようなコードを書いたとしてもうまくいくと...
よってここでは、先に紹介したように、TableLayoutPanelに配...
以下の例では、insertRowの位置に行を挿入しています。サンプ...
#code(vbnet){{
TableLayoutPanel1.SuspendLayout()
Dim c As Control
For Each c In TableLayoutPanel1.Controls
Dim pos As TableLayoutPanelCellPosition = _
TableLayoutPanel1.GetPositionFromControl(c)
TableLayoutPanel1.SetCellPosition(c, pos)
If TableLayoutPanel1.RowCount <= pos.Row Then
TableLayoutPanel1.RowCount = pos.Row + 1
End If
If TableLayoutPanel1.ColumnCount <= pos.Column Then
TableLayoutPanel1.ColumnCount = pos.Column + 1
End If
Next c
'列を増やす
TableLayoutPanel1.RowCount += 1
'コントロールを移動
Dim y As Integer
For y = TableLayoutPanel1.RowCount - 1 To insertRow Step -1
Dim x As Integer
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, y)
If Not (c Is Nothing) Then
TableLayoutPanel1.SetCellPosition( _
c, New TableLayoutPanelCellPosition(x, y ...
End If
Next x
Next y
'スタイルを挿入
If TableLayoutPanel1.RowStyles.Count > insertRow Then
TableLayoutPanel1.RowStyles.Insert( _
insertRow, New RowStyle(SizeType.AutoSize))
End If
TableLayoutPanel1.ResumeLayout()
}}
#code(csharp){{
tableLayoutPanel1.SuspendLayout();
foreach (Control c in tableLayoutPanel1.Controls)
{
TableLayoutPanelCellPosition pos =
tableLayoutPanel1.GetPositionFromControl(c);
tableLayoutPanel1.SetCellPosition(c, pos);
if (tableLayoutPanel1.RowCount <= pos.Row)
tableLayoutPanel1.RowCount = pos.Row + 1;
if (tableLayoutPanel1.ColumnCount <= pos.Column)
tableLayoutPanel1.ColumnCount = pos.Column + 1;
}
//列を増やす
tableLayoutPanel1.RowCount++;
//コントロールを移動
for (int y = tableLayoutPanel1.RowCount - 1; y >= insertR...
{
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosit...
if (c != null)
{
tableLayoutPanel1.SetCellPosition(
c, new TableLayoutPanelCellPosition(x, y ...
}
}
}
//スタイルを挿入
if (tableLayoutPanel1.RowStyles.Count > insertRow)
{
tableLayoutPanel1.RowStyles.Insert(
insertRow, new RowStyle(SizeType.AutoSize));
}
tableLayoutPanel1.ResumeLayout();
}}
***行や列を削除する [#ja25e47e]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelの行や列を削除する>...
}}
これもやはりうまい方法がありませんが、前と同じ方針で行っ...
以下の例では、removeRowの位置の行を削除しています。サンプ...
#code(vbnet){{
TableLayoutPanel1.SuspendLayout()
Dim c As Control
For Each c In TableLayoutPanel1.Controls
Dim pos As TableLayoutPanelCellPosition = _
TableLayoutPanel1.GetPositionFromControl(c)
TableLayoutPanel1.SetCellPosition(c, pos)
If TableLayoutPanel1.RowCount <= pos.Row Then
TableLayoutPanel1.RowCount = pos.Row + 1
End If
If TableLayoutPanel1.ColumnCount <= pos.Column Then
TableLayoutPanel1.ColumnCount = pos.Column + 1
End If
Next c
'削除する列にあるコントロールを削除
Dim x As Integer
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, remov...
If Not (c Is Nothing) Then
TableLayoutPanel1.Controls.Remove(c)
End If
Next x
'コントロールを移動
Dim y As Integer
For y = removeRow + 1 To TableLayoutPanel1.RowCount - 1
For x = 0 To TableLayoutPanel1.ColumnCount - 1
c = TableLayoutPanel1.GetControlFromPosition(x, y)
If Not (c Is Nothing) Then
TableLayoutPanel1.SetCellPosition( _
c, New TableLayoutPanelCellPosition(x, y ...
End If
Next x
Next y
'列を減らす
If TableLayoutPanel1.RowCount > 0 Then
TableLayoutPanel1.RowCount -= 1
End If
'スタイルを削除
If TableLayoutPanel1.RowStyles.Count > removeRow Then
TableLayoutPanel1.RowStyles.RemoveAt(removeRow)
End If
TableLayoutPanel1.ResumeLayout()
}}
#code(csharp){{
tableLayoutPanel1.SuspendLayout();
foreach (Control c in tableLayoutPanel1.Controls)
{
TableLayoutPanelCellPosition pos =
tableLayoutPanel1.GetPositionFromControl(c);
tableLayoutPanel1.SetCellPosition(c, pos);
if (tableLayoutPanel1.RowCount <= pos.Row)
tableLayoutPanel1.RowCount = pos.Row + 1;
if (tableLayoutPanel1.ColumnCount <= pos.Column)
tableLayoutPanel1.ColumnCount = pos.Column + 1;
}
//削除する列にあるコントロールを削除
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosition(...
if (c != null)
{
tableLayoutPanel1.Controls.Remove(c);
}
}
//コントロールを移動
for (int y = removeRow + 1; y < tableLayoutPanel1.RowCoun...
{
for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++)
{
Control c = tableLayoutPanel1.GetControlFromPosit...
if (c != null)
{
tableLayoutPanel1.SetCellPosition(
c, new TableLayoutPanelCellPosition(x, y ...
}
}
}
//列を減らす
if (tableLayoutPanel1.RowCount > 0)
tableLayoutPanel1.RowCount--;
//スタイルを削除
if (tableLayoutPanel1.RowStyles.Count > removeRow)
{
tableLayoutPanel1.RowStyles.RemoveAt(removeRow);
}
tableLayoutPanel1.ResumeLayout();
}}
このように、実行時にTableLayoutPanelに行や列を挿入あるい...
***セルを独自に描画する [#i0b8cefe]
#column(注意){{
この記事の最新版は「[[TableLayoutPanelのセルを独自に描画...
}}
TableLayoutPanelのCellPaintイベントにより、セルを独自に描...
次の例では、一つおきのセルに色をつけています。サンプル「T...
#code(vbnet){{
'TableLayoutPanel1のCellPaintイベントハンドラ
Private Sub TableLayoutPanel1_CellPaint( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TableLayoutCellPaintE...
Handles TableLayoutPanel1.CellPaint
'一つおきにセルの背景色を変更する
If (e.Column Mod 2 = 1) Xor (e.Row Mod 2 = 1) Then
e.Graphics.FillRectangle(Brushes.LightSkyBlue, e....
End If
End Sub
}}
#code(csharp){{
//tableLayoutPanel1のCellPaintイベントハンドラ
void tableLayoutPanel1_CellPaint(object sender,
TableLayoutCellPaintEventArgs e)
{
//一つおきにセルの背景色を変更する
if (e.Column % 2 == 1 ^ e.Row % 2 == 1)
{
e.Graphics.FillRectangle(Brushes.LightSkyBlue, e....
}
}
}}
***継承したコントロールでデザイナを使ってFlowLayoutPanel...
#column(注意){{
この記事の最新版は「[[継承したコントロールでデザイナを使...
}}
FlowLayoutPanelを配置したコントロール(フォームを含む)を...
-[[Bug Details: Form designer doesn’t allow to modify pro...
FlowLayoutPanelについての解決法が次のページで紹介されてい...
-[[FDBK37485#1: Can manage to use FlowLayoutPanel with so...
これによると、FlowLayoutPanelを継承したクラスを作成し、こ...
つまり、例えばまず次のようなクラスを作成し、
#code(vbnet){{
<System.ComponentModel.Designer( _
"System.Windows.Forms.Design.PanelDesigner, System.Design...
Public Class InheritableFlowLayoutPanel
Inherits FlowLayoutPanel
Public Sub New()
End Sub
End Class
}}
#code(csharp){{
[Designer("System.Windows.Forms.Design.PanelDesigner, Sys...
public class InheritableFlowLayoutPanel : FlowLayoutPanel
{
public InheritableFlowLayoutPanel()
{
}
}
}}
これをFlowLayoutPanelの代わりに使うようにします。
残念ながらこれはFlowLayoutPanelだけの解決法で、TableLayou...
**コメント [#r099905e]
#comment
//これより下は編集しないでください
#pageinfo([[:Category/.NET]],2006-06-05 (月) 06:00:00,DOB...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]